DateTime.Time

Updated on

DateTime.Time is a Power Query M function that returns the time part of the provided dateTime value. The function returns the time component of the given datetime value.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

DateTime.Time( dateTime as any ) as nullable time

Description

DateTime.Time returns the time part of the given dateTime argument, which can be of type datetime or datetimezone.

Examples

Let’s explore some practical examples to understand the DateTime.Time function better.

Retrieving the Time from a DateTime Value

You can extract the time component from a specific datetime using the DateTime.Time function. Here’s a simple example:

// Output: #time( 14, 30, 0 )
DateTime.Time( #datetime( 2024, 12, 31, 14, 30, 0 ) ) 

In this example, the function takes the datetime December 31, 2024, 14:30:00, and returns #time( 14, 30, 0 ) as the time component.

To illustrate further, imagine a column in your data that contains various datetime values. Using the DateTime.Time function on this column would extract the time component from each datetime:

DateTime.Time extracts the time value from a datetime value in power query m

Extracting Time from a Date Value

The DateTime.Time function is designed to extract time values. That means you can use it on datetime but also on datetimezone values:

// Output: #time( 12, 0, 0 )
DateTime.Time( #datetimezone( 2026, 7, 25, 12, 0, 0, 2, 30 ) ) 

Here, the function extracts the time 12:00:00 from the datetimezone value July 25, 2026, 12:00:00 PM with a timezone offset of +02:30.

Handling Null Values

The DateTime.Time function also handles null values. When it encounters a null value, it simply returns null instead of an error:

DateTime.Time( null ) // Output: null

This makes sure that your queries are can handle missing or incomplete data without returning an error.

Other functions related to DateTime.Time are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/datetime-time

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy