开发者

About DatePart in Date functions

开发者 https://www.devze.com 2023-04-10 00:46 出处:网络
I couldn\'t understand the difference between SELECT DATEDIFF(D,\'07/09/1978\',GETDATE()) SELECT DATEDIFF(DD,\'07/09/1978\',GETDATE())

I couldn't understand the difference between

SELECT DATEDIFF(D,'07/09/1978',GETDATE())

SELECT DATEDIFF(DD,'07/09/1978',GETDATE())
开发者_运维问答

Both are giving the same value. Then what is the difference between D, and DD?

I have the same question for

  • M, MM
  • Q, QQ
  • YY, YYYY

Can anybody please explain this to me?


Here is a reference on dateparts and what they mean:

  • DATEPART (Transact-SQL) (MSDN)

As you can see, the examples you gave are all identical. However, I know some experts like Aaron Bertrand advocate not using any of the abbreviations, but spelling out the datepart.

See his excellent post on this subject here:

  • Bad Habits to Kick : Using shorthand with date/time operations
0

精彩评论

暂无评论...
验证码 换一张
取 消