“I’ve got a date in the format MMddyyyy and I’d like to convert it into dd/MM/yyyy, how can I do that in Power Automate?”
The standard date format used in Power Automate is ISO 8601. You get dates in this format, use it as a basis when formatting the date, and often also to save them. But not all systems provide the date in the desired format. Since Power Automate can process inputs from various sources, the date format can vary a lot. You might receive attachments with timestamp as MMddyyyy, while the users expect that the date will be dd/MM/yyyy. How do you convert the date? Would you try to do some combination of many expressions to split the date and put it back together? Or do you prefer a simple solution with just 2 expressions?
Convert the date into ISO date
Conversion of a custom formatted date into another custom formatted date will take two steps. Firstly, convert the custom date into an ISO date. Secondly, take the ISO date and convert it into the desired format.
The easiest way to convert any date into an ISO date is to use the parseDateTime(…) expression. Let’s take the MMddyyyy date 05212022 as an example:
parseDateTime('05212022', 'en-US', 'MMddyyyy')
…and convert the date into an ISO formatted date.
Convert the ISO date into different format
The ISO date itself is not pretty enough to show it to the users, but it’s the standard format for a flow. As such you can use the formatDateTime(…) expression to format it. The expression below:
…will format the date as:
Combine the expressions
Now you can do it all in a single step by combining the two expressions.
formatDateTime(parseDateTime(<theDate>, <locale>, <sourceFormat>), <targetFormat>)
Note: <…> are placeholders, replace them including the < and >.
Following with the example from above:
formatDateTime(parseDateTime('05212022', 'en-US', 'MMddyyyy'), 'dd/MM/yyyy')
If you need to convert a date into another format in your Power Automate flow, you should consider using a middle step. Not trying to “brute force” the conversion, but converting it into another data format that’s easier to work with. In this case it was the conversion into ISO date that made the formatting much simpler, in other situations it can be splitting a string into an array to skip some parts of it.