Search code examples
sql-servert-sqldateadd

What is different between DATEADD(DAY, 1, GETDATE()) and DATEADD(DAY, 1, DATEDIFF(DAY, 0, GETDATE()))


What is different between

DATEADD(DAY, 1, GETDATE())

and

DATEADD(DAY, 1, DATEDIFF(DAY, 0, GETDATE()))

Could someone help to show example case, how to use them?


Solution

  • The first version includes the time component of GETDATE(). The second does not. So, if the current time is 2018-01-01T05:43:26, then the first version returns:

    2018-01-02T05:43:26
    

    The second removes the time component, so it returns:

    2018-01-02T00:00:00
    

    I think a better version to get midnight when the next day starts is:

    dateadd(day, 1, cast(getdate() as date))