You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns the count (signed big integer) of the specified *datepart* boundaries crossed between the specified *startdate* and *enddate*.
32
+
This function returns the count (as a signed big integer value) of the specified *datepart* boundaries crossed between the specified *startdate* and *enddate*.
33
33
34
-
For an overview of all [!INCLUDE[tsql](../../includes/tsql-md.md)] date and time data types and functions, see [Date and Time Data Types and Functions (Transact-SQL)](../../t-sql/functions/date-and-time-data-types-and-functions-transact-sql.md).
34
+
See [Date and Time Data Types and Functions (Transact-SQL)](../../t-sql/functions/date-and-time-data-types-and-functions-transact-sql.md) for an overview of all [!INCLUDE[tsql](../../includes/tsql-md.md)] date and time data types and functions.
35
35
36
36
[Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
Is the part of *startdate* and *enddate* that specifies the type of boundary crossed. The following table lists all valid *datepart* arguments. User-defined variable equivalents are not valid.
47
+
The part of *date* to which `DATEDIFF_BIG` adds an **integer***number*. This table lists all valid *datepart* arguments.
48
+
49
+
> [!NOTE]
50
+
> `DATEDIFF_BIG` does not accept user-defined variable equivalents for the *datepart* arguments.
48
51
49
52
|*datepart*|Abbreviations|
50
53
|---|---|
@@ -62,34 +65,42 @@ Is the part of *startdate* and *enddate* that specifies the type of boundary cro
62
65
|**nanosecond**|**ns**|
63
66
64
67
*startdate*
65
-
Is an expression that can be resolved to a **time**, **date**, **smalldatetime**, **datetime**, **datetime2**, or **datetimeoffset** value. *date* can be an expression, column expression, user-defined variable or string literal. *startdate* is subtracted from *enddate*.
66
-
To avoid ambiguity, use four-digit years. For information about two digits years, see [Configure the two digit year cutoff Server Configuration Option](../../database-engine/configure-windows/configure-the-two-digit-year-cutoff-server-configuration-option.md).
68
+
An expression that can resolve to one of the following values:
69
+
70
+
+**date**
71
+
+**datetime**
72
+
+**datetimeoffset**
73
+
+**datetime2**
74
+
+**smalldatetime**
75
+
+**time**
76
+
77
+
For *date*, `DATEDIFF_BIG` will accept a column expression, expression, string literal, or user-defined variable. A string literal value must resolve to a **datetime**. Use four-digit years to avoid ambiguity issues. `DATEDIFF_BIG` subtracts *enddate* from *startdate*. To avoid ambiguity, use four-digit years. See [Configure the two digit year cutoff Server Configuration Option](../../database-engine/configure-windows/configure-the-two-digit-year-cutoff-server-configuration-option.md) for information about two-digit years.
67
78
68
79
*enddate*
69
80
See *startdate*.
70
81
71
82
## Return Type
72
-
Signed
73
-
**bigint**
83
+
84
+
Signed**bigint**
74
85
75
86
## Return Value
76
-
Returns count (signed bigint) of the specified datepart boundaries crossed between the specified startdate and enddate.
77
-
- Each *datepart* and its abbreviations return the same value.
87
+
Returns the count (as a signed bigint value) of the specified datepart boundaries crossed between the specified startdate and enddate.
88
+
- Each specific *datepart* and the abbreviations for that *datepart* will return the same value.
78
89
79
-
If the return value is out of range for **bigint** (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807), an error is returned. For **millisecond**, the maximum difference between *startdate* and *enddate* is 24 days, 20 hours, 31 minutes and 23.647 seconds. For **second**, the maximum difference is 68 years.
90
+
For a return value out of range for **bigint** (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807), `DATEDIFF_BIG` returns an error. For **millisecond**, the maximum difference between *startdate* and *enddate* is 24 days, 20 hours, 31 minutes and 23.647 seconds. For **second**, the maximum difference is 68 years.
80
91
81
-
If *startdate* and *enddate* are both assigned only a time value and the *datepart* is not a time *datepart*, 0 is returned.
92
+
If *startdate* and *enddate* are both assigned only a time value, and the *datepart* is not a time *datepart*, `DATEDIFF_BIG` returns 0.
82
93
83
-
A time zone offset component of *startdate* or *endate* is not used in calculating the return value.
94
+
`DATEDIFF_BIG` does not use a time zone offset component of *startdate* or *enddate* to calculate the return value.
84
95
85
-
Because [smalldatetime](../../t-sql/data-types/smalldatetime-transact-sql.md) is accurate only to the minute, when a **smalldatetime** value is used for *startdate* or *enddate*, seconds and milliseconds are always set to 0 in the return value.
96
+
For a **smalldatetime** value used for *startdate* or *enddate*, `DATEDIFF_BIG` always sets seconds and milliseconds to 0 in the return value because [smalldatetime](../../t-sql/data-types/smalldatetime-transact-sql.md) only has accuracy to the minute.
86
97
87
-
If only a time value is assigned to a variable of a date data type, the value of the missing date part is set to the default value: 1900-01-01. If only a date value is assigned to a variable of a time or date data type, the value of the missing time part is set to the default value: 00:00:00. If either *startdate* or *enddate* have only a time part and the other only a date part, the missing time and date parts are set to the default values.
98
+
If only a time value is assigned to a date data type variable, `DATEDIFF_BIG` sets the value of the missing date part to the default value: 1900-01-01. If only a date value is assigned to a variable of a time or date data type, `DATEDIFF_BIG` sets the value of the missing time part to the default value: 00:00:00. If either *startdate* or *enddate* have only a time part and the other only a date part, `DATEDIFF_BIG` sets the missing time and date parts to the default values.
88
99
89
-
If *startdate* and *enddate*are of different date data types and one has more time parts or fractional seconds precision than the other, the missing parts of the other are set to 0.
100
+
If *startdate* and *enddate*have different date data types, and one has more time parts or fractional seconds precision than the other, `DATEDIFF_BIG` sets the missing parts of the other to 0.
90
101
91
102
## datepart boundaries
92
-
The following statements have the same *startdate* and the same *endate*. Those dates are adjacent and differ in time by .0000001 second. The difference between the *startdate* and *endate* in each statement crosses one calendar or time boundary of its *datepart*. Each statement returns 1. If different years are used for this example and if both *startdate* and *endate* are in the same calendar week, the return value for **week** would be 0.
103
+
The following statements have the same *startdate* and the same *enddate* values. Those dates are adjacent and they differ in time by .0000001 second. The difference between the *startdate* and *enddate* in each statement crosses one calendar or time boundary of its *datepart*. Each statement returns 1. If *startdate* and *enddate* have different year values but they have the same calendar week values, `DATEDIFF_BIG` will return 0 for *datepart***week**.
DATEDIFF_BIG can be used in the select list, WHERE, HAVING, GROUP BY and ORDER BY clauses.
119
+
Use `DATEDIFF_BIG`in the SELECT <list>, WHERE, HAVING, GROUP BY and ORDER BY clauses.
109
120
110
-
DATEDIFF_BIG implicitly casts string literals as a **datetime2** type. This means that DATEDIFF_BIG does not support the format YDM when the date is passed as a string. You must explicitly cast the string to a **datetime** or **smalldatetime** type to use the YDM format.
121
+
`DATEDIFF_BIG` implicitly casts string literals as a **datetime2** type. This means that `DATEDIFF_BIG` does not support the format YDM when the date is passed as a string. You must explicitly cast the string to a **datetime** or **smalldatetime** type to use the YDM format.
111
122
112
-
Specifying SET DATEFIRST has no effect on DATEDIFF_BIG. DATEDIFF_BIG always uses Sunday as the first day of the week to ensure the function is deterministic.
123
+
Specifying SET DATEFIRST has no effect on `DATEDIFF_BIG`. `DATEDIFF_BIG` always uses Sunday as the first day of the week to ensure the function operates in a deterministic way.
113
124
114
-
## Examples
115
-
The following examples use different types of expressions as arguments for the *startdate* and *enddate* parameters.
125
+
## Examples
116
126
117
127
### Specifying columns for startdate and enddate
118
-
The following example calculates the number of day boundaries that are crossed between dates in two columns in a table.
128
+
This example uses different types of expressions as arguments for the *startdate* and *enddate* parameters. It calculates the number of day boundaries crossed between dates in two columns of a table.
119
129
120
130
```sql
121
131
CREATETABLEdbo.Duration
@@ -129,8 +139,8 @@ SELECT DATEDIFF_BIG(day,startDate,endDate) AS 'Duration'
129
139
FROMdbo.Duration;
130
140
-- Returns: 1
131
141
```
132
-
133
-
For many additional examples, see the closely related examples in [DATEDIFF (Transact-SQL)](../../t-sql/functions/datediff-transact-sql.md).
142
+
143
+
See more closely related examples in [DATEDIFF (Transact-SQL)](../../t-sql/functions/datediff-transact-sql.md).
134
144
135
145
## See also
136
146
[CAST and CONVERT (Transact-SQL)](../../t-sql/functions/cast-and-convert-transact-sql.md)
0 commit comments