Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

filter a list by date

Posted on 2015-02-19
3
Medium Priority
?
110 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

609 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