2

Please help me understand the SQL Select statement below:

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

The 0s are throwing me off.

1 Answer 1

5

The date 0 is interpreted as 1/1/1900.

This statement is determining the number of days since 1/1/1900:

DATEDIFF(DAY, 0, GETDATE())

It's wrapped in another call that adds that many days, minus 1, to 1/1/1990 (0).

DATEADD(DAY, <from above> - 1, 0)

Essentially giving you yesterday's date.

Sign up to request clarification or add additional context in comments.

1 Comment

More specifically, it will give you midnight yesterday. It strips the time from the datetime value which getdate() returns.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.