DateTime.ToRecord

DateTime

Converts a datetime value to a record containing its parts.

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

Syntax

DateTime.ToRecord(dateTime as datetime) as record

Parameters

NameTypeRequiredDescription
dateTimedatetimeYesThe datetime value to convert to a record.

Return Value

recordA record with Year, Month, Day, Hour, Minute, and Second fields.

Remarks

DateTime.ToRecord converts a datetime value into a record with the fields Year, Month, Day, Hour, Minute, and Second. Each field contains the corresponding numeric component from the datetime value.

Examples

Example 1: Convert an OrderLog Timestamp to a record

let
    FirstRow = Table.First(OrderLog),
    Rec = DateTime.ToRecord(FirstRow[Timestamp])
in
    #table(
        type table [Year = number, Month = number, Day = number, Hour = number, Minute = number, Second = number],
        {{Rec[Year], Rec[Month], Rec[Day], Rec[Hour], Rec[Minute], Rec[Second]}}
    )
Result
Year
Month
Day
Hour
Minute
Second
12,0241159300

Example 2: Convert a scalar datetime to a record

let
    Rec = DateTime.ToRecord(#datetime(2024, 6, 15, 14, 30, 45))
in
    #table(
        type table [Year = number, Month = number, Day = number, Hour = number, Minute = number, Second = number],
        {{Rec[Year], Rec[Month], Rec[Day], Rec[Hour], Rec[Minute], Rec[Second]}}
    )
Result
Year
Month
Day
Hour
Minute
Second
12,024615143045

Compatibility

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