In this article we will discuss on How to add Hours, Minutes, Seconds to a DateTime in Sql Server?
You may also like to read the following other popular articles on Date and Time in Sql Server:
- How to get Date Part only from DateTime in Sql Server
- How to get Day, Month and Year Part from DateTime in Sql Server
- Difference between DateTime and DateTime2 DataType
- How to get Time, Hour, Minute, Second and Millisecond Part from DateTime in Sql Server
- How to add Days, Weeks, Months, Quarters or Years to a Date in Sql Server
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. Below example shows how we can add two hours to Current DateTime in Sql Server:
SELECT GETDATE() 'Now', DATEADD(hour,2,GETDATE()) 'Now + 2 Hours' SELECT GETDATE() 'Now', DATEADD(hh,2,GETDATE()) 'Now + 2 Hours'
[ALSO READ] How to get difference between two dates in Years, Months and days
How to add Minutes to DateTime in Sql Server?
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. Below example shows how we can add two minutes to Current DateTime in Sql Server:
SELECT GETDATE() 'Now', DATEADD(minute,2,GETDATE()) 'Now + 2 Minutes' SELECT GETDATE() 'Now', DATEADD(mi,2,GETDATE()) 'Now + 2 Minutes' SELECT GETDATE() 'Now', DATEADD(n,2,GETDATE()) 'Now + 2 Minutes'
How to add Seconds to DateTime in Sql Server?
We can use DATEADD() function like below to add seconds to DateTime in Sql Server. DATEADD() functions first parameter value can be second or ss or s all will return the same result. Below example shows how we can add two seconds to Current DateTime in Sql Server:
SELECT GETDATE() 'Now', DATEADD(second,2,GETDATE()) 'Now + 2 Seconds' SELECT GETDATE() 'Now', DATEADD(ss,2,GETDATE()) 'Now + 2 Seconds' SELECT GETDATE() 'Now', DATEADD(s,2,GETDATE()) 'Now + 2 Seconds'
[ALSO READ] How to get difference between two dates in Years, Months and days
this is only for the current date… how to add for an already existing date time column in a table.
Pues solo cambias el valor de GetDate() por tu campo. Fin
DATEADD(hour,2,FechaRegistro)’FechaReg + 2 Horas’
Replace GETDATE() with your date column
Hi,
On the same example you have added 2 hours, How do you add 2.5 hrs ?