Solved

filter a list by date

Posted on 2015-02-19
3
104 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 33

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…

763 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