Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add or subtract time from datetime in SQL server

I have a column offset in db as varchar(50) which contains a value such as 05:30:00 or -2:15:00.

I need to add or subtract this value from another column which is a DATETIME datatype as 2011-07-22 14:51:00.

like image 411
vksh Avatar asked Jun 23 '11 03:06

vksh


People also ask

Can we subtract time in SQL?

MySQL SUBTIME() FunctionThe SUBTIME() function subtracts time from a time/datetime expression and then returns the new time/datetime.

How do I add 5 hours to time in SQL?

How to add Hours to DateTime in Sql Server? We can use DATEADD() function like below to add hours to DateTime in Sql Server. DATEADD() functions first parameter value can be hour or hh all will return the same result.


Video Answer


1 Answers

try something like -

select convert(datetime, '05:30:00') + GETDATE()
like image 113
Paul McLean Avatar answered Nov 15 '22 06:11

Paul McLean