Power Automate formatdatetime [with real examples]

In this Power Automate tutorial, I will explain with examples of format date time in Power Automate. We will also the below topics on Power Automate formatdatetime function.

  1. Power Automate formatDateTime function
  2. Power Automate formatDateTime Date & Time
  3. Power Automate formatDateTime current date
  4. Power Automate formatDateTime Variable
  5. Power Automate formatDateTime Date only
  6. Power Automate formatDateTime “MM/dd/yyyy”
  7. Power Automate formatDateTime AM/PM
  8. Power Automate formatDateTime ISO 8601
  9. Power Automate formatDateTime 24 hours
  10. Power Automate formatDateTime date as number
  11. Power Automate formatDateTime date as Day
  12. Power Automate formatDateTime Null
  13. Power Automate formatDateTime TimeZone
  14. Power Automate formatDateTime Local Time
  15. Power Automate formatDateTime Long Date
  16. Power Automate formatDateTime Short Date
  17. Power Automate formatDateTime Add days
  18. Power Automate formatDateTime Subtract Days

Power Automate Date and Time

Many a time, we are required to send a date (or date & Time) value in an email or append a date value (like created date) to a file using Power Automate. However, formatting date and time can be a bit challenging in MS Flow.

Let’s first see an example of how a date and time value looks in Power Automate without formatting.

Power Automate Date and Time Value without formatting
Power Automate Date and Time Value without formatting

In this Power Automate flow, we first initialize the variable “standarddatetime” and we are setting the current timestamp utcNow() as value for the variable “standarddatetime” and passing the same to the email body

Power Automate Date and Time Value in Email
Power Automate Date and Time Value

Without any formatting, the email will look something like this, and it is not in the standard format, also it is hard to read.

Power Automate formatDateTime function

To get a decent or convenient date & time format, we use formatDateTime() function in Power Automate Flow. This is done by passing the DateTime value and formatting style to formatDateTime() function.

The format styles control the visibility, and positioning of the month, day, hour, second, etc. of the DateTime value. Let’s understand how we can format date and time values in an MS Flow using some examples.

Power Automate formatDateTime Date & Time

Let’s see an example where there is a requirement to display the Date and Time in an email inside a flow using Power Automate. To achieve that we will be using the format style ‘dd/MM/yyyy hh:mm tt in the above function.

power automate formatdatetime
Power Automate formatDateTime Function

So, we are basically passing the current timestamp as a string parameter and the required formatting style in the function and then setting our variable “standarddatetime” to pass it on in the email body.

Here is the expression:

formatDateTime(utcNow(),'dd/MM/yyyy hh:mm tt')

Once, we run the flow, we will receive the below email with date and time output.

format date time power automate
format date time power automate

And this is how we can format the Date and Time value in Power Automate. Let’s see more such examples of format date time power automate.

Power Automate formatDateTime current date

One of the most used and important functions in Power Automate to do with DateTime is utcNow(). You will find this function under “Expression Tab” when adding data to input. The function utcNow() returns current DateTime in the format of “yyyy-MM-ddTHH:mm:ssZ”.

Power Automate formatDateTime Variable

When there is a requirement to append DateTime to a SharePoint file or any document via Power Automate, it is always better to create a variable to store our formatted date time value.

To do that, we need to first initialize the variable by providing the name and data type (in our case, the data type is a string) and then set the variable with a static or dynamic formatted DateTime value.

Power Automate formatDateTime Variable
Power Automate formatDateTime Variable

In the above example, we have seen how to assign the current date and time in the variable “standarddatetime” in Power Automate and we will be using this same variable throughout this tutorial.

Power Automate formatDateTime Date only

Now let’s see another formatting style, suppose we want to send only the date value in the email using Power Automate. To get the date value only, we will be passing the format style “dd/MM/yyyy ” in our formatDateTime() function.

Here, we are using the same variable that we created in the above example and setting the current date value in ‘dd/MM/yyyy format.

Power Automate format Date Only
Power Automate Format Date Only

Here is the expression:

formatDateTime(utcNow(),'dd/MM/yyyy')

After applying the format style of “dd/MM/yyyy“, we will receive the date and time value as 06/07/2022 in the email.

Power Automate format Date Only as output
Power Automate format Date Only as output

So, whenever there is date-only formatting required in Power Automate, we will simply pass the format style ”dd/MM/yyyy to the function.

Power Automate formatDateTime “MM/dd/yyyy”

In another example, where the date is required in “mm/dd/yyyy” format in email using Power Automate. First, we will initialize our variable as shown in the above example, and then set the variable “standarddatetime” with the formatted current date in ‘MM/dd/yyyy’ style and we will pass the variable in the email body.

Power Automate format Date "mm/dd/yyyy"
Power Automate format Date “mm/dd/yyyy”

Here is the expression:

formatDateTime(utcNow(),'MM/dd/yyyy')

After applying the above formatting style, we receive the below email with the formatted date as 09/06/2022

Power Automate format Date "mm/dd/yyyy" as output
Power Automate format Date “mm/dd/yyyy” as output

and that’s how we format the date in “MM/dd/yyyy” style in Power Automate.

Power Automate formatDateTime AM/PM

Let’s see how to retrieve AM/PM value from DateTime in Power Automate. Here, we will be providing time format specifiers like “dd“, “tt” to display result strings. By default, result strings reflect the formatting conventions of the en-US culture.

So, we will pass this format specifier with the current date and time to our variable “standarddatetime“.

Power Automate format Date AM/PM
Power Automate format Date AM/PM

Here is the expression:

formatDateTime(utcNow(),'tt')

For more information about the custom date and time format specifiers, see the MS Documentation

Power Automate format Date AM/PM output
Power Automate format Date AM/PM output

And as we can see, just by applying this custom specifier, we can get the AM/PM from the current date in Power Automate.

Power Automate formatDateTime ISO 8601

To display the DateTime value in ISO standard format in Power Automate, we are going to use the parseDateTime() function by providing the data string, locale, and format style.

Here, we will parse the given date string with en-US culture and also format the date in ‘MM/dd/yyyy‘ and set the variable with the same to use in the email body.

Power Automate format Date  ISO 8601
Power Automate format Date ISO 8601

Here is the expression:

parseDateTime('01/13/2022','en-US','MM/dd/yyyy')

Let’s see the email that we will receive after formatting and just by looking at the output we can tell that it is in ISO standard format.

Power Automate format Date  ISO 8601 as output
Power Automate format Date ISO 8601 as output

In the above example, we have seen how to format date in ISO standard in Power Automate.

Power Automate formatDateTime 24 hours

Many organizations prefer to use 24 hours time format rather than 12 hours. Let’s see how can we get time in 24 hours format using Power Automate.

We will simply be converting the current UTC in 24 hours by providing the 24 hours format style to our function. Let’s see the below example.

Power Automate format Time 24 hours
Power Automate format Time 24 hours

In this example, we are specifying the format as ‘HH:mm:ss‘ so that our formatDateTime() function understands that we need the current time in 24 hours format.

Here is the expression:

formatDateTime(utcNow(),'HH:mm:ss')
Power Automate format Time 24 hours as output
Power Automate format Time 24 hours as output

Here, we can see that the time is displayed in 24 hours in the above email, generated via flow and this is how to format time in 24 hours in Power Automate.

Power Automate formatDateTime date as number

To get the day of the month, from 01 through 31 in Power Automate, we can use another custom format specifier “dd“. Now, here we will be passing the current DateTime string with “dd” format specifier (NOTE: these custom format specifiers are case-sensitive) in our formatDateTime() function in the “expression tab” of flow:

formatDateTime(utcNow(),'dd')

Power Automate formatDateTime date as Day

Similar to the above example, we can also retrieve the day of the week from the current DateTime value in Power Automate. The custom format specifier “ddd” with DateTime value in formatDateTime() function will provide the abbreviated name of the day of the week.

Power Automate format Date as Day
Power Automate format Date as Day

Here in flow, we are populating the pre-initialized variable called “standarddatetime” with current UTC and applying formatting by defining the required custom format specifier.

Here is the expression:

formatDateTime(utcNow(),'ddd')
Power Automate format Date as Day output
Power Automate format Date as Day output

After applying the formatting, we will receive the above email with the output as ‘Tue’ and this is how we can format date as Day in Power Automate.

Power Automate formatDateTime Null

We cannot format an empty date in Power Automate, the input of formatDateTime() expression must always be a valid string. In scenarios where data is a mandatory field in your flow and if some users forget to provide data, this will fail the flow leading to an error message.

To avoid this, we can use the if(…) expression in Power Automate which is similar to the ‘Condition’ action to check the empty DateTime value. In if(..) expression, we define a condition and action if the condition is true or false.

Power Automate format Date Null
Power Automate format Date Null

Before setting the current UTC value in our variable “standarddatetime“, we are using the compose action of Power Automate to check if the current UTC is empty, if it is empty we are setting the action to be performed as null and if it is not empty, we are going to format the date.

Here is the expression

if(empty(utcNow()), null, formatDateTime(utcNow(),'dd/MM/yyyy'))

This is how we can build our flow to check Null date and time value in Power Automate.

Power Automate formatDateTime TimeZone

Let’s discuss a scenario where the client wants to get DateTime in their local timezone in email in a flow using Power Automate. In such a case, we need to convert the local or source timezone to clients or destination timezone.

We will first take the ‘Convert time zone‘ action in the flow and set the Base time with the current UTC or any dynamic date time value, we will also specify the source timezone and required destination timezone.

After defining the destination timezone, we can also apply the format style in the Convert Time Zone action.

Let’s see the below example, where we will convert the IST time zone to the EST timezone while applying the general data/time format style.

Power Automate format Date Time Zone
Power Automate format Date Time Zone

There are various formatting styles given in the Convert Time Zone action and we can also apply custom format styles. Here, we have seen how to convert and format time zone in Power Automate and now let’s see how we can convert it to the local time zone.

Power Automate formatDateTime Local Time

Similarly, if we want to change the timezone to our local time in Power Automate, we will be using the source time zone as UTC and the destination as IST timezone.

In the above example, we converted the source timezone to the client’s destination timezone, here we will convert any universal time zone to our local time zone.

Power Automate format Date Local Time
Power Automate format Date Local Time

As explained in the earlier example, we are using the “Convert time zone” action and setting the base time as the system’s current UTC and destination will be our local time zone.

Once, the time zone is converted to local time, we can then use the converted time to either populate our variable or directly pass it to the email body.

Power Automate formatDateTime Long Date

Now, we will see how to get the long date format by using another custom format specifier “D” in Power Automate.

Power Automate format Long Date
Power Automate format Long Date

Here, we are again taking our variable “standarddatetime” to store the current date and time value. By passing the format specifier ‘D’, we are letting the formatDateTime() function know that we want the date in the Long Date format.

These custom format specifiers come really handy when it comes to formatting date and time in Power Automate.

Here is the expression:

formatDateTime(utcNow(),'D')
Power Automate format Long Date output
Power Automate format Long Date output

and this is how the long date will be displayed in email using Power Automate.

Power Automate formatDateTime Short Date

Let’s see how to convert the current UTC date time to a short date in Power Automate. We are using the same variable “standarddatetime” to store the current date and time and passing another custom format specifier ‘d‘ and then we will be using our variable in the email body.

Power Automate format Short Date
Power Automate format Short Date

Note: Custom format specifiers are case-sensitive, so what happens if we pass the format specifier as ‘d’ and not ‘D’? We will get short-date formatting.

Here is the expression:

formatDateTime(utcNow(), 'd')

Now, we can see the output below in the email.

Power Automate format Short Date output
Power Automate format Short Date output

and this is how we can retrieve short date from the current UTC in Power Automate.

Power Automate formatDateTime Add days

Suppose we have an item in a Sharepoint list with its created date and we have another column called ‘expiration date’. The ‘expiration date’ column should be auto-populated with the date 5 days after the created date column value.

Power Automate Add Days
Power Automate Add Days

We can achieve this by adding the required number of days to the created date in Power Automate. In such a case, we will use the addDay() function and simultaneously format the DateTime.

Here is the expression:

formatDateTime(addDays(utcNow(),5),'dd/MM/yyyy'
Power Automate Add Days output
Power Automate Add Days output

And we will be getting the above email with output as created date + 5 days and this is how we add days in Power Automate.

Power Automate formatDateTime Subtract Days

Let’s see how to subtract days from the created date in the above example in Power Automate. We need now to subtract 5 days from the current date or any dynamic/static value.

Power Automate Subtract Days
Power Automate Subtract Days

Here, we will be again using the addDays() function of Power Automate but instead of 5, to subtract the days we will use ‘-5’, and below is the email with the output date in Power Automate.

Here is the expression:

formatDateTime(addDays(utcNow(),-5),'dd/MM/yyyy')

Once we run the flow, we will receive the below email with output as the created date – 5 days and this is how you can subtract any number if days from your date value in Power Automate.

Power Automate Subtract Days output
Power Automate Subtract Days output

In this flow tutorial, we have seen how to format Date and Time values in Power Automate using formatDateTime() function with several custom format specifiers and formatting styles.

We have covered the below topic:

  • Power Automate Date and Time
  • Power Automate formatDateTime function
  • Power Automate formatDateTime Date & Time
  • Power Automate formatDateTime current date
  • Power Automate formatDateTime Variable
  • Power Automate formatDateTime Date only
  • Power Automate formatDateTime “MM/dd/yyyy”
  • Power Automate formatDateTime AM/PM
  • Power Automate formatDateTime ISO 8601
  • Power Automate formatDateTime 24 hours
  • Power Automate formatDateTime date as number
  • Power Automate formatDateTime date as Day
  • Power Automate formatDateTime Null
  • Power Automate formatDateTime TimeZone
  • Power Automate formatDateTime Local Time
  • Power Automate formatDateTime Long Date
  • Power Automate formatDateTime Short Date
  • Power Automate formatDateTime Add days
  • Power Automate formatDateTime Subtract Days
>