Solved

filter a list by date

Posted on 2015-02-19
3
93 Views
Last Modified: 2015-02-19
I have  a list that currently has data it is called mylog
I want to filter on that list by 2 datetime fields from and to. I have 2 datetimepickers for from and to - I want the user to be able to select dates and filter the current list and display only that data
The field in the list to be filtered is

DateTime myt = mylog.ExpandedSurveyData[i].OriginalSurveyData.SurveyTime;

Open in new window

I tried this just to see what would happen but its wrong
var query = mylog.ExpandedSurveyData[0].OriginalSurveyData.SurveyTime.Where(l => l.DateValue.IsBetween(start, End));

Open in new window

0
Comment
Question by:r3nder
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
it_saige earned 500 total points
ID: 40619916
Quick and dirty example:
using System;
using System.Collections.Generic;
using System.Linq;

namespace EE_Q28620540
{
	class Program
	{
		static List<LogEntry> logEntries = new List<LogEntry>();

		static void Main(string[] args)
		{
			for (int i = 0; i < 100; i++)
				logEntries.Add(new LogEntry() { Start = DateTime.Now.AddDays(i), End = DateTime.Now.AddDays(i + 1).AddHours(i), Message = string.Format("Log Entry {0}", i), Severity = (Severity)(i % 5) });

			DateTime start = DateTime.Now.AddDays(30);
			DateTime end = DateTime.Now.AddDays(50);
			var query = (from entry in logEntries where (entry.Start >= start) && (entry.End <= end) select entry);
			foreach (var entry in query)
				Console.WriteLine(entry);

			Console.ReadLine();
		}
	}

	class LogEntry
	{
		public DateTime Start { get; set; }
		public DateTime End { get; set; }
		public string Message { get; set; }
		public Severity Severity { get; set; }

		public override string ToString()
		{
			return string.Format("{0}: {1}; {2} - {3}", Severity, Message, Start.ToString("MM/dd/yyyy"), End.ToString("MM/dd/yyyy"));
		}
	}

	enum Severity
	{
		Debug = 0,
		Information = 1,
		Warning = 2,
		Error = 3,
		Fatal = 4
	}
}

Open in new window

Produces the following output -Capture.JPG-saige-
0
 
LVL 6

Author Comment

by:r3nder
ID: 40620034
that does it for me thanks saige
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40620035
Thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now