473,657 Members | 2,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date comparison not working in LINQ?

5 New Member
Hi

I've got the following function:

Expand|Select|Wrap|Line Numbers
  1.    public static List<Order> FilterByDateRange(List<Order> _list,string _sdate, string _edate)
  2.     {
  3.       if (_list.Count == 0) return null;
  4.       DateTime _start = Convert.ToDateTime(_sdate);
  5.       string[] _ed = _edate.Split(' ');
  6.       string _edate2 = _ed[0] + " 23:59:59";
  7.       DateTime _end = Convert.ToDateTime(_edate2);
  8.       List<Order> result = (from obj in _list
  9.                             where
  10.                               (((DateTime)obj.DespatchDate >= _start) &&
  11.                               ((DateTime)obj.DespatchDate <= _end))
  12.                             select obj).ToList();
  13.       return result;
  14.     }
The idea being I supply a List of Orders, and I select all the Orders in that set that lie within a date range (note start date starts at 00:00:00 and end date ends at 23:59:59)

I have three orders where obj.DespatchDat e equals
{18/02/2010 18:03:01}
{20/02/2010 14:01:51}
{20/02/2010 14:02:03}

I supply a date range that gives
_start = {20/02/2010 00:00:00}
_end = {22/02/2010 23:59:59}

Problem: result always gets a Count = 0 where I would expect a Count of 2. I stepped through the code and very carefully checked the values of the various dates, so I know they are correct.

Am I being incredibly stupid (certainly not an impossibility) or does date comparison not work in LINQ?

PS. obj.DespatchDat e is type (DateTime?) - but that should not make any difference
Feb 22 '10 #1
1 8974
leosuth
5 New Member
OK 'pologies all.

It turned out that I WAS being stupid :)

My Orders were actually in January and I was looking in February - so date comparison in Linq DOES work just fine!
Feb 22 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2972
by: Daniel Fisher | last post by:
Hi All! I'm fairly new to PhP and basicly trying to learn right now. Now I have a problem - I have a fairly large collection of movies which people keep borrowing from me. And then not returning. So I've put together an Access database with three tables - my media library, a list of friends and email addresses, and a borrow table which uses foreign keys from the other two tables to see who has borrowed what. Borrow Table also has two...
2
10203
by: Scott Knapp | last post by:
Good Day - I have a form which sets the current date, as follows: <script type="text/javascript"> xx=new Date() dd=xx.getDate() mm=xx.getMonth()+1 yy=xx.getYear() mmddyy=mm+"/"+dd+"/"+yy document.write(mmddyy)
4
5364
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
3
11578
by: Lyn | last post by:
Hi, I am developing a project in which I am checking for records with overlapping start/end dates. Record dates must not overlap date of birth, date of death, be in the future, and must not overlap existing records from the same table. I had this all working some time ago, but recently when I have gone back to do more testing, part of these validations no longer work. While there have been changes to the code in the meantime, I cannot...
6
8488
by: MarkAurit | last post by:
Im having difficulty coming up with a good algorithm to express the following comparison: "if <a given date> falls between the (current date - 5 days) and the (current date)" Obviously. DateTime.Now and something like (AddDays(DateTime.Now,-5) are used for the inner and outer ranges, its how to express the "between" that has me. /* what Id like to do, in pseudo code */ dateToTest=DateTime.Parse("mm/dd/yy");
3
10220
by: Tiya | last post by:
Hi there !!! I would like to know how to compare dates in javascript. var sdate = new Date(theform.SubmissionDate.value); var odate = new Date(theform.StartDate.value); var todaysdate = new Date(); if(sdate < todaysdate)
4
3748
by: blini | last post by:
Helo.... How I can convert string "26/03/2006 15:51" for a date? I need to convert and to compare if "09/06/2006 14:20" is lesser or equal that the current date. Everything in Javascript.
7
3885
by: Brett_A | last post by:
I have the following code: If ad_expiration_date (date() + 90) then ad_expiration_date = (date() + 90) else end if What I want to happen is if the ad_expiration_date entered by the user is beyond 90 days from today's date, the Expiration Date should be today's date plus 90 days. If the entered date is less than 90 days
4
7404
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system date is retrieved like this: curDt = new Date();
11
3539
by: Andrus | last post by:
I created dynamic extension methods for <= and < SQL comparison operators: public static IQueryable<TLessThanOrEqual<T>(this IQueryable<Tsource, string property, object value); public static IQueryable<TLessThan<T>(this IQueryable<Tsource, string property, object value); For example var q = db.Customers.LessThanOrEqual( "City", "London" );
0
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.