Sai
Sai

Reputation: 21

Understanding of DATEDIFF() function in SQL server

select DATEDIFF(m,0,GETDATE()) as date

when I execute the query I got answer as 1407 but I am unable to get in which format the answer is in, can anyone explian

Upvotes: 0

Views: 469

Answers (3)

Vinoth_S
Vinoth_S

Reputation: 1530

Your output 1407. so from 1900 to 2017 we have totally 1407 months.because you using the parameter as m

Upvotes: -1

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239654

DATEDIFF takes three parameters - the datepart that describes what units you want the result to be in and two dates.

In your case, you're passing a value of 0 as the second argument, which gets implicitly converted to the datetime 1900-01-01T00:00:00.000.

There are currently 1407 months between 1st January 1900 and today.

Upvotes: 4

steffmaster
steffmaster

Reputation: 132

You set the format with first param, in your case months

possible values are listed here: https://www.w3schools.com/sql/func_datediff.asp

And as shown in the example on w3, you can also use the name of the format, i.e. select DATEDIFF(month,0,GETDATE()) as date

Upvotes: -1

Related Questions