the tables I'll be working on are using DateTime Fields. But I'll be sending just two dates and I would want them to be all encompassing dates. Should I then just add a time of 00:00:00 for the startdate and a time of 23:59:59 for the endtime? or is there a better way? Hi, well, first, at a basic level,
DateTime StartDate = DateTime.Today.AddDays(-7); // everything from a week ago, to today
DateTime EndDate = DateTime.Now;
string FilterExpr =
" WHERE OrderDate BETWEEN '" + StartDate.ToShortDateString() + "' AND '" + EndDate.ToShortDateString() + "'";
Basically, you have to stick a single quote inside the filter string, both before and after the date value.
Now, that code assumes that the dates themselves are stored just as dates (and times are 00:00). Note the use of the ShortDateString function.
However, if your data is stored in sql server as both date and time, then yes, you'd need to do somethign like you described with the ending time (construct something manually....like EndDate.ToShortDateString() + " 11:59:59 PM"
Hope that helps...