DATEDIFF (SQL Server Compact)
Returns the number of date and time boundaries crossed between two specified dates.
Syntax
DATEDIFF ( datepart , startdate , enddate )
Arguments
- datepart
The parameter that specifies on which part of the date to calculate the difference. For more information, see the "Remarks" section later in this topic.
startdate
The beginning date for the calculation. The startdate argument is an expression that returns a datetime value or a Unicode character string in a date format.If you specify only the last two digits of the year, values less than or equal to the last two digits of the value of the two digit year cutoff configuration option are in the same century as the cutoff year. Values greater than the last two digits of the value of this option are in the century that comes before the cutoff year. For example, if the two digit year cutoff is 2049 (the default value), the '49' is interpreted as 2049 and '50' is interpreted as 1950. To avoid ambiguity, use four-digit years.
For more information about how to specify dates, see datetime in Data Types.
- enddate
The ending date for the calculation. The enddate argument is an expression that returns a datetime value or a Unicode character string in a date format.
Return Value
int
Remarks
The following table lists the datepart options and abbreviations recognized by SQL Server Compact 3.5.
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 |
Code Example
The following example determines the number of days it took to ship the orders made by a company that has a Customer ID of 'VINET'.
SELECT [Order ID], DATEDIFF(d, [Order Date], [Shipped Date]) AS [Shipping Time in Days] FROM Orders WHERE ([Customer ID] = 'VINET')
This is the result set:
OrderID Shipping Time in Days
-------------------------------------
10295 8
10737 7
10274 10
10248 12
10739 5