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?
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.
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.
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.
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))".
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With