If you want to convert a value like text, a date, or a number into a proper datetime in Power Query, the DateTime.From function does exactly that. It takes a value and returns a datetime, with an optional culture setting to handle ambiguous text.
Syntax of DateTime.From Function
DateTime.From(value as any, optional culture as nullable text) as nullable datetime
where:
- value (required,
any): The value you want to convert into adatetime. This can be text, adate, adatetimezone, or a number. - culture (optional,
nullable text): A culture code such as"de-DE"that tells Power Query how to read an ambiguous text value. It only applies whenvalueis text.
Returns: A datetime value built from the supplied value. If value is null, the function returns null.
Put simply, DateTime.From reads whatever you hand it and gives you back a single date-and-time value.
Example 1: Convert a Text Timestamp Into a Datetime
Say you have a one-cell table named TextTimestamp with a column Raw. The cell holds the text 2024-03-15 14:30:00, which looks like a timestamp but is really just a string.
This query reads that cell and converts it with DateTime.From.
let
Source = Excel.CurrentWorkbook(){[Name="TextTimestamp"]}[Content],
Raw = Source{0}[Raw],
Converted = DateTime.From(Raw),
Result = DateTime.ToText(Converted,"yyyy-MM-dd HH:mm:ss")
in
Result
Result: 2024-03-15 14:30:00
DateTime.From returns a real datetime value here. The DateTime.ToText step is only there so the result shows as readable text on the page, much like Date.ToText does for a date. A raw datetime would otherwise display as a serial number.
Example 2: Convert a Date Into a Datetime
You can also feed in a date value. Here the input is #date(2024,3,15), which carries no time part.
let
Source = DateTime.From(#date(2024,3,15)),
Result = DateTime.ToText(Source,"yyyy-MM-dd HH:mm:ss")
in
Result
Result: 2024-03-15 00:00:00
When the input is a plain date, the time component defaults to midnight, 00:00:00. The Result is the datetime, shown as text through DateTime.ToText.
Example 3: Convert an Excel Serial Number Into a Datetime
You can convert a number too. Power Query reads it as an OLE Automation date serial, where the whole part is the day count and the fraction is the time of day.
The input 45366.5 has a .5 fraction, which is half a day, so it lands on noon.
let
Source = DateTime.From(45366.5),
Result = DateTime.ToText(Source,"yyyy-MM-dd HH:mm:ss")
in
Result
Result: 2024-03-15 12:00:00
The 45366 part gives the date and the .5 adds twelve hours, so the time reads 12:00:00. The Result is the datetime, shown as text.
Example 4: Parse a Text Value With a Specific Culture
Some text values are ambiguous. The string 15.03.2024 14:30:00 uses a dd.MM.yyyy layout, which Power Query will not read correctly under the default culture.
Passing "de-DE" as the culture argument tells it to read the day first.
let
Source = DateTime.From("15.03.2024 14:30:00","de-DE"),
Result = DateTime.ToText(Source,"yyyy-MM-dd HH:mm:ss")
in
Result
Result: 2024-03-15 14:30:00
The culture argument is what makes this work. Without it, 15.03.2024 could fail or be misread, since 15 cannot be a month. The Result is the datetime, shown as text.
Example 5: Handle a Null Input
When the input is null, DateTime.From returns null rather than throwing an error. This query checks that behavior with an equality test.
let
Source = DateTime.From(null),
Result = Source = null
in
Result
Result: true
DateTime.From(null) returns null, so the comparison Source = null evaluates to true. This makes the function safe to run against columns that may contain blanks. If you later need that value as a string, Number.ToText and DateTime.ToText give you formatting control over the output.
Things to keep in mind with DateTime.From
- The function returns a
datetime, which holds both a date and a time. It is not the same asdate(date only) ordatetimezone(date, time, plus an offset). - When you pass a
datevalue, the time part is set to00:00:00. - A number input is read as an OLE Automation date serial. The integer part is the day count and the decimal fraction is the fraction of a day.
- The
cultureargument only matters for ambiguous text. It is ignored when the value is adate, number, or other non-text type. - An unparseable string throws an error. For example,
DateTime.From("not a date")raisesExpression.Error: We couldn't parse the input provided as a DateTime value. - A
nullinput returnsnull, so the function will not break on blank cells.
Common questions about DateTime.From
How do I keep the result as a real datetime instead of text?
Drop the DateTime.ToText step. The examples wrap the output in DateTime.ToText only so the value displays cleanly here. If you want a working datetime, return Converted directly, or use Table.TransformColumnTypes to set the column type to datetime in your applied steps.
What is the difference between DateTime.From and DateTime.FromText?
DateTime.FromText only accepts text and parses it as a datetime. DateTime.From is broader. It also converts dates, numbers, and datetimezone values, so it is the more flexible choice when your input type can vary.
List of All Power Query Functions
Related Power Query Functions / Articles: