DateTime.Time

DateTime

Returns the time part from a datetime value.

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

Syntax

DateTime.Time(dateTime as any) as nullable time

Parameters

NameTypeRequiredDescription
dateTimeanyYesThe datetime value to extract the time from.

Return Value

timeThe 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
1L0011/15/2024 9:30:00 AM09:30:00
2L0021/16/2024 2:15:00 PM14:15:00
3L0031/18/2024 11:00:00 AM11:00:00
4L0041/20/2024 8:45:00 AM08:45:00
5L0052/1/2024 4:20:00 PM16: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
13/15/2024 2:30:45 PM14:30:45

Compatibility

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