Tag Archives: dateadd

Set Date Back Twelve Hours – MSSQL

Hey everyone,

A quick post on how to set a date value for twelve hours ago using SQL Server:

UPDATE MyTable
SET MyDate = dateadd(HOUR, -12, CURRENT_TIMESTAMP)

Simply use the dateadd function and specify the unit (hours in this case). The example above will set MyDate to twelve hours ago.

Here’s the offical documentation on the function: https://docs.microsoft.com/en-us/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-2017

Also, thanks to this stackoverflow post for the info: https://stackoverflow.com/a/18518412/522859

Advertisements