Skip to content

Format a date in a specific format

Power Automate Desktop has an action for getting the current date, so getting it is easy, but working with the date you get takes a little ingenuity.

Also, when you get the current date, the variable that’s created is stored as the Datetime type, so you need to be careful when you use it.

This article explains how to format date data in a specific format.

The Datetime type is a value with multiple properties, and you can get date-related data by specifying something like %VariableName.Year%.

However, to use it as a string, you need to format it, which you do with the “Convert datetime to text” action.

If you choose “Standard” for “Format to use,” you can pick from templates such as short date, long date, and sortable datetime, so you generally don’t need to build a format yourself. If you need your own format, choose “Custom” and specify it with format specifiers like the following (.NET custom date and time format strings). Note that uppercase and lowercase letters have different meanings.

Specifier Meaning
yyyy Year (4 digits)
MM Month (2 digits)
dd Day (2 digits)
HH Hour (24-hour clock, 2 digits)
hh Hour (12-hour clock, 2 digits)
mm Minute (2 digits)
ss Second (2 digits)
fff Milliseconds (3 digits; ff goes to hundredths of a second)
zzz Offset from UTC (for example, +09:00)

Copy the following code and paste it into the Power Automate Desktop flow designer to add the actions.

DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> Current
Text.ConvertDateTimeToText.FromCustomDateTime DateTime: Current CustomFormat: $'''yyyy/MM/dd HH:mm:ss.fff zzz''' Result=> Formatted
  1. In “Search actions,” type “Get current date and time” and set the parameters as follows.

    Parameter Value
    Retrieve Current date and time
    Time zone System time zone
    Variables produced %Current%
  2. Again in “Search actions,” type “Convert datetime to text” and set the parameters as follows.

    Parameter Value
    Datetime to convert %Current%
    Format to use Custom
    Custom format yyyy/MM/dd HH:mm:ss.fff zzz
  3. Set “Custom format” to the format you want to use and run the flow to display the current date in any format.