I have an sql DateTime (ms sql server) and want to extract the same date without the seconds:
e.g. 2011-11-22 12:14:58.000 to become: 2011-11-22 12:14:00.000
How can I do this? I was thinking to use DATEADD in combination with DATEPART but seems very error prone (besides performance issues)
For a solution that truncates using strings try this:
CHAR(16) works only if our variable is converted to ODBC canonical format, as shown above by using
20as the format specifier.Results:
Then you simply cast back to a DateTime type to continue using the value.