I have a table that has a datetime field called [avg time to answer]. For certain records the time is displaying incorrectly as shown below:
1899-12-30 01:04:00.000
1899-12-30 01:05:00.000
1899-12-30 01:30:00.000
The times shown here are wrong. Times shown above are as small sample but they need to be formatted in minutes seconds rather than hours and minutes
Is there a way to correct this with a SQL script as the alternative involves extracting the data again and that is going to be extremely difficult and time consuming to do.
You can use DATEPART:
Combined with DATEADD:
Example:
This casts the value to a
date, to strip off the time portion and back to adatetimeto set the time to00:00:00. Then adds minutes based on the hour value and seconds based on the minute value.You can use this with an
UPDATEstatement, but ensure you use aWHEREclause to avoid updating everything, unless that's what you intend.Example Update Query: