473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Date comparison not working in LINQ?

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.DespatchDate 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.DespatchDate is type (DateTime?) - but that should not make any difference
Feb 22 '10 #1
1 8840
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
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....
2
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...
4
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...
3
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...
6
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....
3
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...
4
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
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...
4
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.