Introduction
In Power Automate, the formatDateTime expression is a function that allows you to format a date and time into a specific format. This is especially useful when you need to display or use dates and times in a certain way for your workflows, such as in emails, notifications, or further logic
For example in power automate the expression utcNow() would give us an output:
Year-Month-DayTHour:Minute:Second.FractionalSecondsZ
2025-03-17T09:30:34.0601101Z
Popular Date Formats
Here are some of the most common date formats used:Input | 2025-03-17T09:30:00.0000000Z |
---|---|
Expression | formatDateTime(‘2025-03-17T09:30:00.0000000Z’,’dd/MM/yyyy’) |
Output | 17/03/2025 |
Input | 2025-03-17T09:30:00.0000000Z |
---|---|
Expression | formatDateTime(‘2025-03-17T09:30:00.0000000Z’,’d, MMMM, yyyy’) |
Output | 3, March, 2025 |
Input | 2025-03-17T09:30:00.0000000Z |
---|---|
Expression | formatDateTime(‘2025-03-17T09:30:00.0000000Z’,’dddd, d, MMMM, yyyy’) |
Output | Monday 3, March 2025 |
Popular Time Formats
Here are some of the most common Time formats used:Input | 2025-03-17T15:30:00.0000000Z |
---|---|
Expression | formatDateTime(‘2025-03-17T15:30:00.0000000Z’,’HH:mm’) |
Output | 15:30 |
Input | 2025-03-17T15:30:00.0000000Z |
---|---|
Expression | formatDateTime(‘2025-03-17T15:30:00.0000000Z’,’hh:mm tt’) |
Output | 03:30 PM |
Input | 2025-03-17T15:30:00.0000000Z |
---|---|
Expression | formatDateTime(‘2025-03-17T15:30:00.0000000Z’,’HH:mm:ss’) |
Output | 15:30:00 |
More complex Date Formatting
One more common date format but is harder to implement is the ordinal numbers. For example a date that is 16/03/2025 you want to read 16th March 2025
The code below checks common ordinal numbers e.g. 1 would be 1st 2 would be 2nd and adds ‘st‘, ‘nd‘, ‘rd‘ and ‘th‘ depending on the number, it also checks to make sure there is no leading ‘0’ for example ‘03/03/2025‘ should read ‘3rd March 2025‘ not ‘03rd March 2025‘ it then uses ‘concat’ to join the string with the month and year
@{concat(
formatDateTime(utcNow(), 'dd'),
if(and(greaterOrEquals(int(formatDateTime(utcNow(), 'dd')), 11), lessOrEquals(int(formatDateTime(utcNow(), 'dd')), 13)),
'th',
if(equals(mod(int(formatDateTime(utcNow(), 'dd')), 10), 1), 'st',
if(equals(mod(int(formatDateTime(utcNow(), 'dd')), 10), 2), 'nd',
if(equals(mod(int(formatDateTime(utcNow(), 'dd')), 10), 3), 'rd', 'th')))),
' ',
formatDateTime(utcNow(), 'MMMM yyyy')
)
}