+1  A: 

Try with

DateTime today = DateTime.Today;

if does not solve, check whether your date field contains time also. there lies your problem.

Update: your second comment.

when you compare with DateTime.Now e.g. Date <= 21.12.2009 14:35:35, it will take all before 14:35 hours and will ignore later rows. Hope this helps you.

See following article to get more idea

http://dotnetguts.blogspot.com/2007/06/understanding-datetime-and-timespan-in.html

Saar
Works fine when time not set (using DateTime.Today for example). But that is not enough.
Tadas
What do you need more?
Saar
What you've suggested - that's not the solution. That works when time is not set. But why it is not working with time? Why operator >= works and <= not? What I've posted here is just a test/example. I'm looking for more general explanation.
Tadas
+1  A: 

The date comparison takes the time into account. So, for instance, "today at midday" is greater than just "today". If you use DateTime.Now, the time is included. So, if DateTime.Now is "today at midday", then tomorrow = today.AddDays(1) is less than "tomorrow at 3PM"... So you need to ignore the time part of the date. You can do that by formatting the date without the time. Also, if you want to check that a date is "less or equal than tomorrow" (regardless of the time), check that it is "strictly less than the day after tomorrow" :

string filter = string.Format(CultureInfo.InvariantCulture,
                "Date >= #{0:MM/dd/yyyy}# AND Date < #{1:MM/dd/yyyy}#",
                yesterday,
                tomorrow.AddDays(1));
Thomas Levesque
+1  A: 

The code you posted in your update is not equivalent to the row filter. Your row filter formats the date using the general format for the current culture. This probably does not include fractions of a second - therefore unless you happen to call DateTime.Now on a second boundary, your tomorrow value will be some fractions of a second beyond the range specified by the filter.

I.e. if your tomorrow value is '2009-12-23 01:02:03.456', your row filter is only taking values up to and including '2009-12-23 01:02:03', a few fractions of a second before the value specified by tomorrow.

If you only want to compare dates, you should use DateTime.Date to truncate the time component from your dates (and use DateTime.Today rather than DateTime.Now for the current date).

Joe