Friday, February 17, 2006

sql datetime selection

select Convert(varchar(20), mydatefield, 101) from mytable

gives a list like
01/24/2007
01/26/2007
01/27/2007

takes a datetime field, pulls out the date and then you can use it as you wish. This would come in handy when you use a "between date1 and date2". The "date2" might account for the time 00:01 on that date, so if you have something saved for 10:05 on that date, it would not correctly appear when you execute the between statement. So we use the convert (see above) to chop the time off, so we're doing pure date comparisons and tests.