Time.From

Updated on

Time.From is a Power Query M function that converts various input values into a time value, with an optional culture parameter. The function returns a time value derived from the given input value.

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

Syntax

Time.From(
   value as any,
   optional culture as nullable text,
) as nullable time
ArgumentAttributeDescription
valueThe value to extract a time value from.
cultureoptionalThe culture argument enables the specification of a Culture code (e.g., “nl-NL” or “en-US”) to align transformations with local formatting conventions. If this argument is omitted, functions default to Culture.Current, which reflects the system’s regional settings.

Description

The Time.From function in Power Query extracts time values from various data types, including text, datetime, datetimezone, and number values. It converts the input into a time format, returning only the time component (hours, minutes, and seconds) and discarding any date or timezone information.

If the input value is null, Time.From returns null. If the input is already a time value, it is returned unchanged. The function returns an error if any other type of value is used as input. An optional culture parameter (e.g., “nl-NL”) can also be provided.

Examples

Let’s see how the Time.From function works with some examples.

Extract Time From a Text Value

You can extract values from different types. For instance, to extract a time value from a text value, you could use:

Time.From( "05:30:44" ) // Output: #time( 5, 30, 44 )

This format uses a string structured as “hours:minutes.” The Time.From function can handle many different string formats to extract time values. Here are some additional examples:

Time.From Extracts a Time Value from A String in Power Query M

For more detailed information, make sure to check out the supported formats at the Time.FromText function.

Extract Time From a DateTime Value

Another way to obtain a time value is by extracting it from a datetime value. For example, to extract the time component from the value September 15, 2024, 09:35:10, you can use the following code:

// Output: #time( 9, 35, 10 )
Time.From( #datetime( 2024, 9, 15, 09, 35, 10 ) )

This operation returns only the time component of the datetime value, which in this case is 09:35:10.

Extract Time From a DateTimeZone Value

You can also extract the time component from a datetimezone value. This process is similar to extracting time from a datetime value. Here’s an example:

// Output: #time( 19, 15, 01 )
Time.From( #datetime( 2024, 9, 15, 19, 15, 01, 2, 15 ) )

In this case, the function extracts only the time component and discards the date and timezone information. The result is the time value 19:15:01.

Extract Time From a Number Value

The Time.From function can also extract a time value from a number. As long as the number is positive and less than 1, the function will return a correct result. For instance, to return the value corresponding to noon, you can provide the value 0.5 to the function:

// Output: #time( 12:00:00 )
Time.From( 0.5 )

You can also return a more detailed version of a time. For example, using 0.6725 as input:

// Output: #time( 16, 8, 24 )
Time.From( 0.6725 ) 

In this example, 0.6725 corresponds to the time 16:08:24.

Other functions related to Time.From are:

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

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