DateTime.ToRecord
DateTimeConverts a datetime value to a record containing its parts.
Syntax
DateTime.ToRecord(dateTime as datetime) as recordParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | datetime | Yes | The datetime value to convert to a record. |
Return Value
record — A 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 | |
|---|---|---|---|---|---|---|
| 1 | 2,024 | 1 | 15 | 9 | 30 | 0 |
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 | |
|---|---|---|---|---|---|---|
| 1 | 2,024 | 6 | 15 | 14 | 30 | 45 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks