How do I add 1 hour to datetime SQL column data? How do I add 1 hour to datetime SQL column data? sql-server sql-server

How do I add 1 hour to datetime SQL column data?


Use DATEADD()

DATEADD(hh, 1, order_date)

EDIT:

If the time is being set an hour back, you may have a wrong system time. So, it would be better if you just ask server admin to correct it.


You should consider using DATETIMEOFFSET as your daatype instead of DATETIME.

Defines a date that is combined with a time of a day that has time zone awareness and is based on a 24-hour clock.

You can use it with SYSDATETIMEOFFSET().

Returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is included.

Example:

 CREATE TABLE DateTest (id INT, order_date DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET()) INSERT INTO DateTest (id) VALUES (1) SELECT * FROM DateTest