DateTime.From

Updated on

DateTime.From is a Power Query M function that returns a datetime value from the given value, with optional culture specification. It can convert text, date, datetimezone, time, and number types to a datetime value.

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

Syntax

DateTime.From(
   value as any,
   optional culture as nullable text,
) as nullable datetime
ArgumentAttributeDescription
valueThe value to extract a datetime 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

DateTime.From returns a datetime value from the given value. Optional culture parameter (e.g., “en-US”) may also be provided. If the input is null, the function returns null. If the input is already a datetime, it returns the same value.

Supported input types and their conversions include:

  • Text: Converted to datetime, see DateTime.FromText for details.
  • Date: Returns datetime with the input date and a time component of 12:00:00 AM.
  • Datetimezone: Converted to local datetime.
  • Time: Returns datetime with an OLE Automation Date of 0 as the date and the input time.
  • Number: Converted to datetime equivalent of the OLE Automation Date .

An error is returned for any other input type.

Examples

Convert #time( 06, 45, 12 ) to a datetime value.

// Output: #datetime( 1899, 12, 30, 06, 45, 12 )
DateTime.From( #time( 06, 45, 12 ) )

Convert #date( 1975, 4, 4 ) to a datetime value.

// Output: #datetime( 1975, 4, 4, 0, 0, 0 )
DateTime.From( #date( 1975, 4, 4 ) )

Other functions related to DateTime.From are:

BI Gorilla Youtube Channel

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