DateTimeZone.FromText
Reads a date, time and offset from text, such as an ISO timestamp from an API.
Group: Dates and times. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
DateTimeZone.FromText(text as nullable text, optional options as any) as nullable datetimezone
| Parameter | Type | Description |
|---|---|---|
text | nullable text | The text to read; null gives null. |
options | any optional | A record [Format = ..., Culture = ...], both fields optional, or a culture's name as text. Left out, the query's culture reads the text. |
Returns
nullable datetimezone. The datetimezone; an error when the text cannot be read.
Remarks
- The offset comes after the time, as +01:00 or -05:00; a Z means UTC.
- The offset is kept as written: the clock time is not moved to UTC. Use
DateTimeZone.ToUtcfor that. - Text without an offset is the computer's clock time and gets the computer's offset at that date. The computer's time zone is the one of the computer that runs the query, with its summer time: the studio's on your desk, the server's when a model refreshes there. These examples ran in Oslo (+01:00 in winter, +02:00 in summer).
Compared with Power Query
Known difference in OpenBI Studio 0.3.79, found while this page was written and run on its engine:
DateTimeZone.FromText("Tue, 05 Mar 2024 10:00:00 GMT", [Culture = "en-US"]): Power Query, on a computer at +01:00, gives #datetimezone(2024, 3, 5, 10, 0, 0, 1, 0): the clock time of the text with the computer's offset. OpenBI keeps the offset the text names, GMT's: #datetimezone(2024, 3, 5, 10, 0, 0, 0, 0).
Examples
An ISO timestamp with an offset
DateTimeZone.FromText("2024-03-15T14:30:00+01:00")
#datetimezone(2024, 3, 15, 14, 30, 0, 1, 0)
A UTC timestamp
DateTimeZone.FromText("2024-03-15T13:30:00Z")
#datetimezone(2024, 3, 15, 13, 30, 0, 0, 0)
Related functions
DateTimeZone.From, DateTimeZone.ToText, DateTime.FromText, DateTimeZone.ToUtc.