DateTime.Type

DateTime.Type is a Type Value that represents all date and time values without an associated timezone. It is used to classify the data type of a value. This type is used when dealing with fields that require both date and time information, like timestamps or log entries.

Examples

The best way to understand the usage and functionality of DateTime.Type is through practical examples. Let’s take a few scenarios where DateTime.Type can be crucial.

When adding a new column in Power Query, specifying the data type of the new column is an essential practice. This not only keeps your data consistent but also prevents potential errors or issues that might arise due to data type mismatches.

Consider the following example where we add a new column named “Value” to a table “Source”. You can ascribe a data type to your value by specifying the 4th optional argument of Table.AddColumn.

Table.AddColumn(
   Source, 
   "Value", 
   each DateTime.FromText( "2023-06-07T12:30:45" ), 
   DateTime.Type 
)

DateTime.Type also proves to be invaluable when creating tables from scratch in Power Query. The #table function allows you to specify a data type before providing the desired column values. Consider the following example where we define a column in a table to be of DateTime.Type:

#table( 
   type table [ Value = DateTime.Type ], 
   { { DateTime.FromText("2023-06-07T12:30:45") } } 
   )

Here, we use the #table function to create a new table. The type table statement defines the structure of the table, stating that it will have a column named “Value” of type DateTime. We then provide the DateTime value to populate this column, again using the DateTime.FromText function to convert a string to a DateTime value.

Related type values

Other related type values are:

BI Gorilla Blog

Last update: August 17, 2023 | Contribute » | Contributors: Rick de Groot
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.