开发者

About DatePart in Date functions

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜