Skip to content

Commit 64ffe9f

Browse files
authored
Merge pull request #689 from fbsolo/patch-40
Update datediff-big-transact-sql.md
2 parents 3cb56f1 + 40bd137 commit 64ffe9f

1 file changed

Lines changed: 34 additions & 24 deletions

File tree

docs/t-sql/functions/datediff-big-transact-sql.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ manager: craigg
2929
# DATEDIFF_BIG (Transact-SQL)
3030
[!INCLUDE[tsql-appliesto-ss2016-asdb-xxxx-xxx-md](../../includes/tsql-appliesto-ss2016-asdb-xxxx-xxx-md.md)]
3131

32-
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*.
3333

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.
3535

3636
![Topic link icon](../../database-engine/configure-windows/media/topic-link.gif "Topic link icon") [Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
3737

@@ -44,7 +44,10 @@ DATEDIFF_BIG ( datepart , startdate , enddate )
4444

4545
## Arguments
4646
*datepart*
47-
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.
4851
4952
|*datepart*|Abbreviations|
5053
|---|---|
@@ -62,34 +65,42 @@ Is the part of *startdate* and *enddate* that specifies the type of boundary cro
6265
|**nanosecond**|**ns**|
6366

6467
*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.
6778

6879
*enddate*
6980
See *startdate*.
7081

7182
## Return Type
72-
Signed
73-
**bigint**
83+
84+
Signed **bigint**
7485

7586
## 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.
7889

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.
8091

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.
8293

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.
8495

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.
8697

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.
8899

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.
90101

91102
## 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**.
93104

94105
```sql
95106
SELECT DATEDIFF_BIG(year, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000');
@@ -105,17 +116,16 @@ SELECT DATEDIFF_BIG(millisecond, '2005-12-31 23:59:59.9999999', '2006-01-01 00:0
105116
```
106117

107118
## Remarks
108-
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.
109120

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.
111122

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.
113124

114-
## Examples
115-
The following examples use different types of expressions as arguments for the *startdate* and *enddate* parameters.
125+
## Examples
116126

117127
### 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.
119129

120130
```sql
121131
CREATE TABLE dbo.Duration
@@ -129,8 +139,8 @@ SELECT DATEDIFF_BIG(day,startDate,endDate) AS 'Duration'
129139
FROM dbo.Duration;
130140
-- Returns: 1
131141
```
132-
133-
For many additional examples, see the closely related examples in [DATEDIFF &#40;Transact-SQL&#41;](../../t-sql/functions/datediff-transact-sql.md).
142+
143+
See more closely related examples in [DATEDIFF &#40;Transact-SQL&#41;](../../t-sql/functions/datediff-transact-sql.md).
134144

135145
## See also
136146
[CAST and CONVERT &#40;Transact-SQL&#41;](../../t-sql/functions/cast-and-convert-transact-sql.md)

0 commit comments

Comments
 (0)