?
Solved

filter a list by date

Posted on 2015-02-19
3
Medium Priority
?
109 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …
Six Sigma Control Plans
Suggested Courses

765 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