SQL datetime set to midnight
Posted on 2009-07-01
There are two elements to this question, but both simple answers.
1) I have a table of datetimes for which the time component is whenever the record was created. I need a SQL update query to set them all to midnight.
ie to convert 01/05/2009 21:23:22 to 01/05/2009 00:00:00
2) I am running a query which gets all matching records between @fromdate and @todate. Where these are string parameters from user input.
How can I add a time to the parameter like this:
@fromdate must be @fromdate 00:00:00 (ie midnight)
@todate must be @todate 23:59:59 (ie last second of the day).