#datetime
Makes a datetime, a date with a time of day and no time zone, from six numbers.
Group: Dates and times. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
#datetime(year as number, month as number, day as number, hour as number, minute as number, second as number) as datetime
| Parameter | Type | Description |
|---|---|---|
year | number | The year, 1 to 9999. |
month | number | The month, 1 to 12. |
day | number | The day of the month. |
hour | number | The hour, 0 to 23. |
minute | number | The minute, 0 to 59. |
second | number | The second, 0 up to (not including) 60; it may have a fraction. |
Returns
datetime. The moment; an error when the numbers are not a valid date and time.
Remarks
- Year, month, day, hour and minute are whole numbers; the second may carry a fraction, kept to a ten millionth of a second.
- Subtracting one datetime from another gives a duration; adding a duration to a datetime gives a datetime.
Examples
When an order was placed
#datetime(2024, 3, 15, 14, 30, 0)
#datetime(2024, 3, 15, 14, 30, 0)
A fraction of a second
#datetime(2024, 3, 15, 14, 30, 12.5)
#datetime(2024, 3, 15, 14, 30, 12.5)
Hours worked on a shift
#datetime(2024, 3, 15, 17, 0, 0) - #datetime(2024, 3, 15, 8, 30, 0)
#duration(0, 8, 30, 0)
The difference of two datetimes is a duration: 8 hours and 30 minutes.
Related functions
#date, #time, #datetimezone, DateTime.From, DateTime.FromText.