OpenBI Docs Buy

DateTime.ToText

Writes a datetime as text, in the culture's form or in a format you give.

Group: Dates and times. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

DateTime.ToText(dateTime as nullable datetime, optional options as any, optional culture as nullable text) as nullable text
ParameterTypeDescription
dateTimenullable datetimeThe datetime to write; null gives null.
optionsany
optional
A record [Format = ..., Culture = ...], both fields optional; or, as older queries do, a format as text.
culturenullable text
optional
A culture's name, when options is a format given as text.

Returns

nullable text. The datetime as text.

Remarks

  • Text follows the culture: the one given, else the query's (Culture.Current), which is the model's Locale for import, else the model's own culture, else en-US. These examples run in en-US unless a culture is given. Left without a format, en-US writes 3/15/2024 2:30:00 PM; nb-NO writes 15.03.2024 14:30:00.
  • A format is built from letters: yyyy the year, MM the month as two digits, MMM and MMMM its short and full name, dd the day, ddd and dddd the weekday's short and full name, HH the hour on a 24-hour clock, hh on a 12-hour clock with tt for AM or PM, mm minutes, ss seconds. Text in single quotes is copied as it is.
  • "o" gives the full ISO form with seven decimals of the second, good for exchanging data.

Examples

The culture's form

DateTime.ToText(#datetime(2024, 3, 15, 14, 30, 0))
"3/15/2024 2:30:00 PM"

A timestamp for a log

DateTime.ToText(#datetime(2024, 3, 15, 14, 30, 0), [Format = "yyyy-MM-dd HH:mm"])
"2024-03-15 14:30"

In Norwegian

DateTime.ToText(#datetime(2024, 3, 15, 14, 30, 0), [Culture = "nb-NO"])
"15.03.2024 14:30:00"

DateTime.FromText, Date.ToText, Time.ToText, DateTimeZone.ToText.

Last updated · OpenBI Studio 0.3.79