DATEDIFF DAX Function (Date and Time)
Returns the number of units (unit specified in Interval) between the input two dates.
Syntax
Parameter | Attributes | Description |
---|---|---|
Date1 |
A date in datetime format that represents the start date. |
|
Date2 |
A date in datetime format that represents the end date. |
|
Interval |
The unit that will be used to calculate, between the two dates. It can be SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR. |
Return values
The count of interval boundaries crossed between two dates.
Remarks
The result is positive if Date2 is larger than Date1.
The result is negative if Date1 is larger than Date2.
Previous versions of the DAX engine (earlier than 2018) could provide an error if Date1 is larger than Date2.
Examples
-- DATEDIFF computes the delta between two dates, using different units of measure -- YEAFRAC returns the delta as a fraction (in years) EVALUATE VAR StartDate = DATE ( 2011, 01, 01 ) VAR EndDate = DATE ( 2012, 12, 15 ) RETURN { ( "DATEDIFF Year", DATEDIFF ( StartDate, EndDate, YEAR ) ), ( "DATEDIFF Quarter", DATEDIFF ( StartDate, EndDate, QUARTER ) ), ( "DATEDIFF Month", DATEDIFF ( StartDate, EndDate, MONTH ) ), ( "DATEDIFF Day", DATEDIFF ( StartDate, EndDate, DAY ) ), ( "Subtraction-1", INT ( EndDate - StartDate ) ), ( "Subtraction-2", CONVERT ( EndDate - StartDate, INTEGER ) ), ( "YEARFRAC", YEARFRAC ( StartDate, EndDate ) ) }
Value1 | Value2 |
---|---|
DATEDIFF Year | 1.00 |
DATEDIFF Quarter | 7.00 |
DATEDIFF Month | 23.00 |
DATEDIFF Day | 714.00 |
Subtraction-1 | 714.00 |
Subtraction-2 | 714.00 |
YEARFRAC | 1.96 |
Last update: Nov 14, 2024 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo, Ed Hansberry
Microsoft documentation: https://docs.microsoft.com/en-us/dax/datediff-function-dax