DateTimeZone.ToText
Writes a datetimezone as text, offset included, in the culture's form or 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
DateTimeZone.ToText(dateTimeZone as nullable datetimezone, optional options as any, optional culture as nullable text) as nullable text
| Parameter | Type | Description |
|---|---|---|
dateTimeZone | nullable datetimezone | The value to write; null gives null. |
options | any optional | A record [Format = ..., Culture = ...], both fields optional; or, as older queries do, a format as text. |
culture | nullable text optional | A culture's name, when options is a format given as text. |
Returns
nullable text. The value 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, the culture's date and time are followed by the offset. - A format is built from letters:
yyyythe year,MMthe month as two digits,MMMandMMMMits short and full name,ddthe day,dddandddddthe weekday's short and full name,HHthe hour on a 24-hour clock,hhon a 12-hour clock withttfor AM or PM,mmminutes,ssseconds. Text in single quotes is copied as it is.zzzwrites the offset as +01:00.
Examples
The culture's form
DateTimeZone.ToText(#datetimezone(2024, 3, 15, 14, 30, 0, 1, 0))
"3/15/2024 2:30:00 PM +01:00"
An ISO timestamp for an API
DateTimeZone.ToText(#datetimezone(2024, 3, 15, 14, 30, 0, 1, 0), [Format = "yyyy-MM-ddTHH:mm:sszzz"])
"2024-03-15T14:30:00+01:00"
In Norwegian
DateTimeZone.ToText(#datetimezone(2024, 3, 15, 14, 30, 0, 1, 0), [Culture = "nb-NO"])
"15.03.2024 14:30:00 +01:00"
Related functions
DateTimeZone.FromText, DateTime.ToText, DateTimeZone.ZoneHours.