Time.FromText

Updated on

Time.FromText is a Power Query M function that creates a time value from a text representation, with optional formatting and culture options. The function returns the time value corresponding to the provided textual representation.

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

Syntax

Time.FromText(
   text as nullable text,
   optional options as any,
) as nullable time
ArgumentAttributeDescription
timeThe text value to transform into a time value.
optionsoptional
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

Time.FromText converts a string into a time value. It optionally accepts a record parameter named options for specifying detailed properties. This function offers two main fields within the options record:

Format Field: This field, holding a text type, determines the format applied during conversion. If omitted or set to null, the function attempts to interpret the time format in a general manner. Further information about format patterns can be accessed via this link and that link.

Culture Field: This field comes into play when the Format field is not null. It adapts certain format aspects based on cultural settings. For example, under the "en-US" culture, the "tt" format represents either “AM” or “PM”, contrasting with the "ar-EG" culture, where "tt" stands for “ص” or “م”. The default formatting is governed by Culture.Current when this field is absent or null.

The function also retains compatibility with older workflows by accepting a text value for options, equating to options = [Format = null, Culture = options].

Examples

Convert "10:12:31am" into a Time value.

// Output: #time( 10, 12, 31 )
Time.FromText( "10:12:31am" )

Convert "1012" into a Time value.

// Output: #time( 10, 12, 00 )
Time.FromText( "1012" )

Convert "10" into a Time value.

// Output: #time( 10, 00, 00 )
Time.FromText( "10" )

Other functions related to Time.FromText are:

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