DateTime.FromText
Reads a date and time from text: ISO form, the culture's own 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
DateTime.FromText(text as nullable text, optional options as any) as nullable datetime
| 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 datetime. The datetime; an error when the text cannot be read.
Remarks
- Without a format, ISO text (2024-03-15T14:30:00, a space instead of the T is fine) is read, and so is the culture's form (3/15/2024 2:30 PM in en-US). A date without a time reads as midnight.
- Text in UTC, ending in Z or GMT, is moved to the computer's local time. 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).
- With a format, the text must follow it: the letters are those of
DateTime.ToText.
Examples
An ISO timestamp
DateTime.FromText("2024-03-15T14:30:00")
#datetime(2024, 3, 15, 14, 30, 0)
A fixed format from a till system
DateTime.FromText("15.03.2024 14:30", [Format = "dd.MM.yyyy HH:mm"])
#datetime(2024, 3, 15, 14, 30, 0)
The en-US way of writing it
DateTime.FromText("3/15/2024 2:30 PM")
#datetime(2024, 3, 15, 14, 30, 0)
Related functions
DateTime.From, DateTime.ToText, Date.FromText, DateTimeZone.FromText.