DateTime.Time
DateTimeReturns the time part from a datetime value.
Syntax
DateTime.Time(dateTime as any) as nullable timeParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | The datetime value to extract the time from. |
Return Value
time — The time component of the given datetime.
Remarks
DateTime.Time extracts the time component from a datetime or datetimezone value, discarding the date portion. If the input is null, the function returns null.
Examples
Example 1: Extract time from OrderLog Timestamp
Table.AddColumn(
Table.SelectColumns(
Table.FirstN(OrderLog, 5),
{"LogID", "Timestamp"}
),
"TimeOnly", each DateTime.Time([Timestamp]), type time
)Result
LogID | Timestamp | TimeOnly | |
|---|---|---|---|
| 1 | L001 | 1/15/2024 9:30:00 AM | 09:30:00 |
| 2 | L002 | 1/16/2024 2:15:00 PM | 14:15:00 |
| 3 | L003 | 1/18/2024 11:00:00 AM | 11:00:00 |
| 4 | L004 | 1/20/2024 8:45:00 AM | 08:45:00 |
| 5 | L005 | 2/1/2024 4:20:00 PM | 16:20:00 |
Example 2: Extract time from a scalar datetime
#table(
type table [DateTime = datetime, TimeOnly = time],
{{#datetime(2024, 3, 15, 14, 30, 45), DateTime.Time(#datetime(2024, 3, 15, 14, 30, 45))}}
)Result
DateTime | TimeOnly | |
|---|---|---|
| 1 | 3/15/2024 2:30:45 PM | 14:30:45 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks