If you are dealing with dates in your databases DATEDIFF_BIG can be your best friend. You might already know about the function DATEDIFF which has the exact structure of DATEDIFF_BIG. Really the main difference between them is the DATEDIFF returns int and DATEDIFF_BIG returns bigint.
You can use both function in the select list, WHERE, HAVING, GROUP BY and ORDER BY clauses.
DATEDIFF_BIG (datepart, startdate, enddate)
This function returns bigint. startdate and enddate can be time,date,datetime, smalldatetime, datetime2 or datetimeoffset.
Available dataparts:
Available dataparts:
- year (yy, yyyy)
- quarter (qq, q)
- month (mm, m)
- dayofyear (dy, y)
- day (dd, d)
- week (wk, ww)
- hour (hh)
- minute (mi, n)
- second (ss, s)
- millisecond (ms)
- microsecond (mcs)
- nanosecond (ns)

No comments:
Post a Comment