Tag Archives: How to Add Minutes to DateTime in Sql Server

How to add Hours, Minutes, Seconds to a DateTime in Sql Server

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 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'

RESULT:
Add Hours to DateTime in Sql Server

[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'

RESULT:
Add Minutes to DateTime in Sql Server 1

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'

RESULT:
Add Seconds to DateTime in Sql Server

[ALSO READ] How to get difference between two dates in Years, Months and days