A way to extract from a DateTime value data without seconds 1

A way to extract from a DateTime value data without seconds

SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, 0, yourcolumn), 0) FROM yourtable

Here is what the above code is Doing:
1. DATEDIFF(MINUTE, 0, yourcolumn) – This will return the number of minutes between the date 0 and yourcolumn.
2. DATEADD(MINUTE, DATEDIFF(MINUTE, 0, yourcolumn), 0) – This will add the number of minutes between the date 0 and yourcolumn to the date 0.
3. SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, 0, yourcolumn), 0) FROM yourtable – This will return the rounded down date for each row in yourtable.

Similar Posts