3 Ways to Format a Date in Power Automate

Do you need to format the dates in your flow?

Date values are a big part of most datasets. This means you’re likely going to work with them in any workflows.

When working with dates in a flow, you might need to change the format of the date to suit the needs of your audience. For example, you might want to change the format from mm/dd/yyyy to dd/mm/yyyy.

You can change the date format to match just about any pattern!

This post will show you how to change the date format in Power Automate.

Format a Date with the formatDateTime Function

Formatting dates is an important and common task in Power Automate. This is why Power Automate has a dedicated workflow function for formatting dates.

formatDateTime(timestamp, format, locale)

The formatDateTime function will take a date value and format it based on a custom format pattern.

  • timestamp is the date or datetime you want to format.
  • format is the pattern you want your date format to match. You can use a standard format or custom format string.
  • local is the local or region to use for output. en-us is the default.
formatDateTime(outputs('Date'),'dd/MM/yyyy')

In this example, the date inside a compose action is formatted using a dd/MM/yyyy pattern.

When this runs it will result in the date 21/08/2022.

Many other custom date formats are possible. Here is a list of date format codes and their output based on the example date 2022-08-09.

Format CodeDescriptionResult
dSingle digit day9
ddDouble digit day09
dddShort day nameTue
ddddLong day nameTuesday
MSingle digit month8
MMDouble digit month08
MMMShort month nameAug
MMMMLong month nameAugust
ySingle digit year2
yyDouble digit year22
yyyyFull year2022
formatDateTime('2022-08-09', 'dddd, MMMM d, yyyy', 'en-US')

These can be combined in just about any way. For example, this format dddd, MMMM d, yyyy will result in a date like Tuesday, August 9, 2022 for the date 2022-08-09.

Format a Date with the Convert Time Zone Action

Unfortunately, there is no user-friendly action available for the formatDateTime function.

But there still is an action available that can be used to format your dates.

You can use the Convert time zone action since this gives you an extra option to format the output. You just need to convert from and to the same timezone. This will essentially only use the format part of the action.

This way, you get a user-friendly dropdown option to choose your desired date format and don’t need to mess around with the expressions.

  1. Add the Convert time zone action to your flow.
  2. Enter the date or dynamic content referencing the date into the Base time input field.
  3. Select your desired format from the Format string dropdown menu. You can also choose the Enter custom value option and then enter your own custom format code.
  4. Select the same option in both the Source time zone and Destination time zone dropdown menu. For example, you can select UTC Coordinated Universal Time options in both.

When you run this action, it will return the desired format. In this example, you can see the date 2022-08-21 is formatted as Sunday, August 21, 2022.

Format a Date using Format Data by Example

This is a great new option to help you build your own expressions if you’re not comfortable working with the workflow functions.

It will allow you to enter a few examples of the output you desire and then build an expression that will return those results.

  1. Click on any field in Power Automate where you want to return the formatted date.
  2. Go to the Expression tab of the popup.
  3. Select the Format data by examples option.

This will open a side pane on the right and you will be able to choose the date you want to format.

  1. Select the date dynamic content to format. This example is formatting a date from a compose action.

Now you will need to provide at least one example transformation.

  1. Add an Example value for Outputs. This is a sample of what values might be in your dynamic content. Here the date 2022-08-01 is entered.
  2. Enter the Desired output based on the Example value for Output. When you start typing, it will provide you will Suggested transformations that you can select.
  3. Click on the Get expression button.
formatDateTime(parseDateTime(outputs('Date')), 'MMMM d, yyyy', 'en-US')

This will create a Suggested expression for you which you can copy into your clipboard and use in any field of your flow.

You can also test out the new formula on a few other Test value inputs using the Test button. This will help give you confidence that the suggested expression is correct and will provide the results you want!

  1. Click on the Apply button.

This will add the suggested expression to the action from step 1.

Conclusions

Formatting dates is a common task. Different audiences may require different date formats.

It’s possible to format your dates in Power Automate without too much trouble.

Power Automate offers a dedicated formatDateTime function for this purpose, but for a more user-friendly method to format dates, you can also use the Convert time zone action.

Also, you can check out the Data by example feature to help you build an expression if you’re not comfortable with the workflow functions.

How do you format dates in Power Automate? Do you have any other tips? Let me know in the comments below!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

0 Comments

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!