#datetime

DateTime

Creates a datetime value from year, month, day, hour, minute, and second components.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

#datetime(year as number, month as number, day as number, hour as number, minute as number, second as number) as datetime

Parameters

NameTypeRequiredDescription
yearnumberYesThe year component (e.g. 2024).
monthnumberYesThe month component (1–12).
daynumberYesThe day component (1–31, depending on month).
hournumberYesThe hour component (0–23).
minutenumberYesThe minute component (0–59).
secondnumberYesThe second component (0–59, can include fractional seconds).

Return Value

datetimeA datetime value representing the specified date and time.

Remarks

#datetime is M's literal constructor for creating datetime values — a combined date and time with no timezone offset.

The second argument may include fractional seconds (e.g. 30.5 for 30.5 seconds). Out-of-range component values produce an error.

#datetime does not encode a timezone. If you need to represent a specific moment in time relative to UTC, use #datetimezone instead. To strip the time component from a datetime, use DateTime.Date. To extract the time component, use DateTime.Time.

Examples

Example 1: Create a datetime literal

#datetime(2024, 3, 15, 14, 30, 0)
Result
Result
13/15/2024 2:30:00 PM

Example 2: Extract date and time parts

let
    dt   = #datetime(2024, 3, 15, 14, 30, 0),
    d    = DateTime.Date(dt),
    t    = DateTime.Time(dt)
in
    {d, t}
Result
Result
1{2024-03-15, 14:30:00}

Example 3: Subtract two datetimes to get a duration

let
    start  = #datetime(2024, 3, 15, 9, 0, 0),
    finish = #datetime(2024, 3, 15, 17, 30, 0),
    elapsed = finish - start
in
    elapsed
Result
Result
1PT8H30M

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks