#datetime

Updated on

#datetime is a Power Query M function that creates a datetime value from numbers representing the year, month, day, hour, minute, and (fractional) second.

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

Syntax

#datetime(
   year as number,
   month as number,
   day as number,
   hour as number,
   minute as number,
   second as number,
) as datetime

Description

Creates a datetime value from numbers representing the year, month, day, hour, minute, and (fractional) second. Raises an error if these conditions are not true:

  • 1 ≤ year ≤ 9999
  • 1 ≤ month ≤ 12
  • 1 ≤ day ≤ 31
  • 0 ≤ hour ≤ 23
  • 0 ≤ minute ≤ 59
  • 0 ≤ second < 60

Examples

Returns the datetime value of June 10, 2023 (date) 04:08:12 (time).

#datetime( 2023, 6, 10, 4, 8, 12 )

You can easily transform a datetime value into a date or a time value.

= DateTime.Date( #datetime( 2023, 6, 10, 4, 8, 12 ) ) // Returns #date( 2023, 6, 10 )

= DateTime.Time( #datetime( 2023, 6, 10, 4, 8, 12 ) ) // Returns #time( 4, 8, 12 )

Other functions related to #datetime are:

BI Gorilla Blog

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