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

Let’s look at some examples of how the DateTime.From function works.

Convert Time Value

You can convert a #time value to a datetime value by using the following construct:

// Output: #datetime( 1899, 12, 30, 7, 30, 15 )
DateTime.From( #time( 7, 30, 15 ) )

The operation appends the date #date(1899, 12, 30) to your time value and returns the result as a datetime value.

Convert Date Value

You can also retrieve a datetime value from a date value. For instance, when you convert the date December 31, 2024, to a datetime value, this is the result:

// Output: #datetime( 2024, 12, 31, 0, 0, 0 )
DateTime.From( #date( 2024, 12, 31 ) )

The operation appends the time 12:00:00 AM to your date and returns December 31, 2024, 12:00:00 AM.

Extract From DateTimeZone Value

You can also extract a datetime value from a datetimezone value:

// Outcome: #datetime( 2024, 12, 31, 15, 20, 10 )
DateTime.From( #datetimezone( 2024, 12, 31, 15, 20, 10, 3, 0 ) )

The operation discards the timezone components and returns the remaining date and time value.

Convert Text to DateTime

Another option is to extract a datetime value from a text value:

// Output: #datetime( 2024, 9, 31, 6, 45, 20 )
DateTime.FromText( "2024-09-31T06:45:20" )

For more details on valid syntax for extracting a datetime value from a text, please refer to the DateTime.FromText function.

OLE Automation Date Syntax

You can also use the OLE Automation date syntax. This type of date is shown as a floating-point number. The whole number part counts the days before or after midnight on December 30, 1899. The decimal part represents the time of day divided by 24. For example, midnight on December 31, 1899, is represented by 1.0.

For instance:

// Outcome: #datetime( 2026, 1, 28, 12, 0, 0 )
DateTime.From( 46050.0 )

Other functions related to DateTime.From are:

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

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