DATE DAX Function (Date and Time)
Returns the specified date in datetime format.
Syntax
Parameter | Attributes | Description |
---|---|---|
Year |
A four digit number representing the year. |
|
Month |
A number from 1 to 12 representing the month of the year. |
|
Day |
A number from 1 to 31 representing the day of the month. |
Return values
Returns the specified date.
Examples
-- DATE and TIME are useful to create DateTime columns -- A DateTime is a number. Therefore, it is possible to -- sum the date and the time part. EVALUATE { DATE ( 2020, 10, 15 ), TIME ( 22, 45, 30 ), DATE ( 2020, 10, 15 ) + TIME ( 22, 45, 30 ) }
Value |
---|
2020-10-15 00:00:00 |
1899-12-30 22:45:30 |
2020-10-15 22:45:30 |
-- When the arguments overflow their range, DATE and TIME -- behave in different ways: -- -- DATE adds the excess values to the date, moving time forward -- TIME adds the excess values, but it does never exceed the day EVALUATE { DATE ( 2020, 10, 32 ), DATE ( 2020, 20, 1 ), TIME ( 10, 90, 0 ), TIME ( 50, 0, 0 ) }
Value |
---|
2020-11-01 00:00:00 |
2021-08-01 00:00:00 |
1899-12-30 11:30:00 |
1899-12-30 02:00:00 |
-- You can use DATE to create a new date, one year later -- Using built-in functions like EDATE is better, it they are available EVALUATE ADDCOLUMNS( TOPN ( 5, VALUES ( 'Date'[Date] ), 'Date'[Date], ASC ), "One year later", DATE ( YEAR ( 'Date'[Date] ) + 1, MONTH ( 'Date'[Date] ), DAY ( 'Date'[Date] ) ), "One year later (Using EDATE)", EDATE ( 'Date'[Date], 12 ) )
Date | One year later | One year later (Using EDATE) |
---|---|---|
2005-01-05 | 2006-01-05 | 2006-01-05 |
2005-01-04 | 2006-01-04 | 2006-01-04 |
2005-01-02 | 2006-01-02 | 2006-01-02 |
2005-01-01 | 2006-01-01 | 2006-01-01 |
2005-01-03 | 2006-01-03 | 2006-01-03 |
Related functions
Other related functions are:
Last update: Aug 3, 2022 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo
Microsoft documentation: https://docs.microsoft.com/en-us/dax/date-function-dax