LINQ Query / "between" dates
-
Hi All, I've spent way to long on this - I'm trying to get distinct values from a dataTable: begDate = 2007-11-18 / endDate = 2007-12-31 Why does this work: Returns 4 rows Dim shipTo = From row In osDS.Tables(0).AsEnumerable _ Order By row(7) _ Where row(0).ToString = cust _ And row(1).ToString > begDate _ Select row(7) Distinct This doesn't work: Results Empty / Enumeration yield no results.... Dim shipTo = From row In osDS.Tables(0).AsEnumerable _ Order By row(7) _ Where row(0).ToString = cust _ And row(1).ToString < endDate _ Select row(7) Distinct But what I really want is: (but it doesn't work either) Dim shipTo = From row In osDS.Tables(0).AsEnumerable _ Order By row(7) _ Where row(0).ToString = cust _ And row(1).ToString > begDate _ And row(1).ToString < endDate _ Select row(7) Distinct Thanks in advance . . . . MB
-
Hi All, I've spent way to long on this - I'm trying to get distinct values from a dataTable: begDate = 2007-11-18 / endDate = 2007-12-31 Why does this work: Returns 4 rows Dim shipTo = From row In osDS.Tables(0).AsEnumerable _ Order By row(7) _ Where row(0).ToString = cust _ And row(1).ToString > begDate _ Select row(7) Distinct This doesn't work: Results Empty / Enumeration yield no results.... Dim shipTo = From row In osDS.Tables(0).AsEnumerable _ Order By row(7) _ Where row(0).ToString = cust _ And row(1).ToString < endDate _ Select row(7) Distinct But what I really want is: (but it doesn't work either) Dim shipTo = From row In osDS.Tables(0).AsEnumerable _ Order By row(7) _ Where row(0).ToString = cust _ And row(1).ToString > begDate _ And row(1).ToString < endDate _ Select row(7) Distinct Thanks in advance . . . . MB
Are
begDate
andendDate
actually strings with the values "2007-11-18", "2007-12-31" respectively? And what is the type of data inrow(1)
? Is it also a string, or is it a date? If it is a date in that column, then it seems possible that taking theToString()
from date values is not using the same format asbegDate
andendDate
are representing the date. I'd suggest doing the comparison as date (DateTime
) values to avoid any issues with cultural-specific date formatting.