Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add hours to current date in SQL Server?

I am trying to add hours to current time like

-- NOT A VALID STATEMENT -- SELECT GetDate(DATEADD (Day, 5, GETDATE())) 

How can I get hours ahead time in SQL Server?

like image 919
Lakhae Avatar asked Aug 29 '13 18:08

Lakhae


People also ask

How do I add hours to a date in SQL?

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.

How can I add time to date in SQL Server?

select cast(concat(yourDateColumnName, ' ', yourTimeColumnName) as datetime) as anyVariableName from yourTableName; In the above concept, you will use cast() when your date and time is in string format. The cast() function can be used only for datetime. To understand the above syntax, let us create a table.

How can I add 30 minutes to current date in SQL?

We can use DATEADD() function like below to add minutes to DateTime in Sql Server. DATEADD() functions first parameter value can be minute or mi or n all will return the same result.

How can I add hours and minutes in SQL Server?

For your calculation to work you would need 23.983333333*60. I would suggest using for ultimate accuracy (23*60)+59 = 1439. Making the final query "SELECT DATEADD(MINUTE, 1439, CAST('2016-07-08' AS DATETIME))".


2 Answers

DATEADD (datepart , number , date )

declare @num_hours int;      set @num_hours = 5;   select dateadd(HOUR, @num_hours, getdate()) as time_added,         getdate() as curr_date   
like image 133
gloomy.penguin Avatar answered Sep 21 '22 11:09

gloomy.penguin


Select JoiningDate ,Dateadd (day , 30 , JoiningDate) from Emp  Select JoiningDate ,DateAdd (month , 10 , JoiningDate) from Emp  Select JoiningDate ,DateAdd (year , 10 , JoiningDate ) from Emp  Select DateAdd(Hour, 10 , JoiningDate ) from emp   Select dateadd (hour , 10 , getdate()), getdate()  Select dateadd (hour , 10 , joiningDate) from Emp   Select DateAdd (Second , 120 , JoiningDate ) , JoiningDate  From EMP 
like image 20
user6851776 Avatar answered Sep 20 '22 11:09

user6851776