Search code examples
exceleditorbusiness-intelligencepowerquery

How to format a date in Power Query? (Microsoft Excel 2016 - Query Editor - Advanced Editor?)


Using Microsoft Excel 2016 - Query Editor - Advanced Editor.

I am not familiar with this language.

let
   SettingsSheet = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
   #"TimeRange" = Table.TransformColumnTypes(SettingsSheet,{{"From", type datetime}, {"To", type datetime}}),
   From = #"TimeRange"[From],
   #"To" = #"TimeRange"[To],
   DateFormatString = "mm/dd/yy",
   #"FormattedFrom" = Format(From,DateFormatString),
   ...
   (Further in the code I will need to build a URL string from it.)

When I search for the syntax to format date into a string, I always find this Format(...,...) function, but I get the error message

The name 'Format' wasn't recognized. Make sure it's spelled correctly.

What is the correct syntax?


Solution

  • The language is call Power Query. the expression I was looking for is DateTime.ToText(DateTime, DateFormatString) (instead of Format(DateTime, DateFormatString)).