Returns the difference between the two dates.
Syntax
DATEDIFF (datepart ,startdate ,enddate)
datepart | Abbreviations |
---|---|
year | yy, yyyy |
quarter | qq, q |
month | mm, m |
dayofyear | dy, y |
day | dd, d |
week | wk, ww |
weekday | dw |
hour | hh |
minute | mi, n |
second | ss, s |
millisecond | ms |
Example 1 of DATEDIFF()
GetDate() shows todays date.
SELECT DATEDIFF(day,GetDate()-1,GetDate())
1
Example 2 of DATEDIFF()
SELECT DATEDIFF(hh,GetDate()-1,GetDate())
24
Example 3 of DATEDIFF()
SELECT DATEDIFF(mi,GetDate()-1,GetDate())
1440
No comments:
Post a Comment