Power Automate formatDateTime() Function

Are you aware of using the Power Automate formatDateTime() function? If not, go through this tutorial to learn how to change the date and time format.

This tutorial explains the Power Automate formatDateTime() function and its syntax. Also, we will discuss how to use the formatDateTime() Function in Power Automate with various examples.

formatDateTime() function in Power Automate is useful for formatting the date and time values displayed in a flow.

Power Automate formatDateTime() Function

Power Automate format DateTime () function allows for customizing date and time values according to our preferences and displayed.

The formatDateTime is a feature within Microsoft’s Power Platform that enables users to convert a DateTime value into a string value, adhering to the format specified by the user.

The output from the Power Automate formatDateTime() expression will give the updated timestamp in the specified format and locale.

This is the overview of the Power Automate formatDateTime() function.

Power Automate formatDateTime() Syntax

This is how the syntax for the Power Automate formatDateTime() function looks like:

formatDateTime('timestamp', 'format', 'locale')

Parameters:

  • Timestamp: It is a required field where a user can add time to the timestamp.
  • Format: It is an optional field where a user can provide a custom timestamp format. It will take the default format[yyyy-MM-ddTHH:mm: ss.fffffffK] if not provided.
  • Locale: The locale is the local or the region that comes in the output. If not specified by default, it will take a value as en-us. If locale isn’t a valid value, an error is generated.

Example:

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

Let’s say the current date and time is “2023-12-20“. By default, utcNow will return the output as 2023-12-20T05:39:46.2167400Z. But, formatDateTime() will return the format as 20-12-2023[day-month-year].

Microsoft Power Automate formatDateTime() function

This is about the syntax of Power Automate’s formatDateTime() function.

Power Automate formatDateTime() Function Formats

Now, let’s check on some of the Power Automate formatDateTime() function formats used to convert the date time into a specific format.

When working with date and time values in Power Automate, we can see the date and time will not be in a specific format according to our requirements. Microsoft provides the formatDateTime() function to customize our required date format.

The below table will represent some of the different formats that can be used in the formatDateTime ()function:

FormatDescriptionOutput
yyyyyear2023
MMMMMonth nameOctober
ddday11
yyyy-MM-ddYear-Month-Day2023-10-12
yyyy-MM-ddTHH:mm:ssZDate and Time2023-10-12T14:30:00Z
HH: mm12 hour time indicator with AM/PM02:30PM
HH:mm24-hour time indicator 14:30
MMM dd,yyyyMonth Day, YearJul 16, 2023

Power Automate formatDateTime() of UtcNow

In this section, I will show you how to format the date and time of a current date and time in a Power Automate flow.

Example:

Let’s assume the current date and time is “2023-12-20“. By default, utcNow will return the output as 2023-12-20T05:39:46.2167400Z. But, formatDateTime() will return the format as 20-12-2023 [Day-Month-Year Format].

Power Automate formatDateTime() function

A step-by-step guide to get the current date in different formats of Power Automate flow:

1. Navigate to make.powerautomate.com in the browser to open the Power Automate Home page -> Tap on +Create -> Select Instant cloud flow -> Take Manually trigger a flow and enter a flow name -> Click Create.

2. To provide the formatDateTime() function, add an “Initialize variable” flow action and complete the following details:

  • Name: Provide a name for the variable.
  • Type: Set data type as ‘String’ from the drop-down.
  • Value: Provide the expression that is given in below code:
formatDateTime(utcNow(),'dd-MM-yyyy')

Then, Click OK.

Power Automate formatDateTime() for utcNow()

3. Next, add a Compose flow action and select the input generated from the initialized variable.

  • Inputs: Select the field -> Take variable from the dynamic content.
formatDateTime() function in Power Automate

After creating the flow, Save and Test the flow manually.

4. Upon successful execution, the flow is notified that “Your flow ran successfully.” Next, open the compose flow action to view the output, displaying the returns of the formatDateTime() expression in the following format.

  • The return will be as 20-12-2023 in [Day-Month-Year Format].
Power Automate formatDateTime() of UtcNow

This is how to format the utcNow() in day, month, and year format in a Power Automate flow using the formatDateTime() function.

Power Automate formatDateTime() in Year-Month-Date Format

Similarly, in a flow, let’s see how to format utcNow() to Year-Month-Date using a Power Automate formatDateTime() function.

Example:

Assuming the present date to be “20-12-2023“, the default output of utcNow would be “2023-12-20T05:39:46.2167400Z“. Using the formatDateTime() function, the date and time can be represented in a customized format, such as the “Year-Month-Day” format [2023-12-20].

Power Automate utcnow format yyyymmdd

Look at the steps that are mentioned below:

1. In the initialized variable, change the formatDateTime() expression as given in the below code.

  • Name: Provide a name for the variable as utcNow.
  • Type: Set data type as String from the drop-down.
  • Value: Provide the expression that is given in the below code.
formatDateTime(utcNow(),'yyyy-MM-dd')

Then, select OK.

Power Automate formatDateTime() in yyyyMMdd format

2. To see the output, open the compose flow action, and the result can be seen from the below image in Year-Month-Date format.

  • The result from the Power Automate formatDateTime() function is 2023-12-20.
Power Automate formatdatetime(utcnow() 'yyyy-MM-dd')

This is how to work with the Power Automate formatDateTime() function to get the date in Year-Month-Date format.

Power Automate formatDateTime() of utcNow() with Time

Moreover, I will describe one more example of Power Automate formatDateTime() of utcNow() with time.

Example:

Considering the present date and time to be “2023-12-20T07:25:50.1374041Z,” that will be the default output of utcNow. However, using the formatDateTime() function, the date and time can be represented in a customized format, such as year-month-date-Hour-minutes- seconds [2023-12-20T07:25:50].

formatDateTime() of utcNow() using Power Automate

Go through the below-given steps.

1. In the Initialized variable flow action, select the below details:

  • Name: Enter the name of a variable manually.
  • Type: Select datatype from drop-down as String.
  • Value: Click the field -> Select Expression -> Give the below expression.
formatDateTime(utcNow(),'yyyy-MM-ddTHH:mm:ss')

Select OK.

Power Automate formatDateTime() of utcNow() with Time

2. Check out the timestamp retrieved from the formatDateTime () expression in the compose outputs. The result will give a timestamp along with the time [2023-12-20T07:25:50].

 formatDateTime() of utcNow() with Time in Power Automate

This is how to work with Power Automate formatDateTime() expression to get year-month-date-Hour-minutes- seconds format in a flow.

Power Automate formatDateTime() of a Date Variable

Now, let me show you an example of the Power Automate formatDateTime() of a date variable in day, Month name, and Year.

Example:

Let’s give the timestamp as “20-12-2023“. I wanted to format this timestamp in day, month name, and year format. Then, my result will be as of 20 December 2023.

How to use Power Automate formatDateTime() function

To work with this, follow the below-given steps:

1. In the Power Automate, Manually trigger a flow trigger and take the date input like below.

  • Click Add an input -> Select Date.
Power Automate formatDateTime() expression

2. To give the formatDateTime() expression, take an “Initialize variable” flow action and complete the following details:

  • Name: Provide a name as a Date for the variable.
  • Type: Set data type as String from the drop-down.
  • Value: Select the field -> Click Expression -> Give the below place code.
formatDateTime(triggerBody()['date'],'dd MMMM yyyy')

After that, Click OK.

Power Automate formatDateTime() of a Date Variable

3. After saving the flow, run it manually. In the Runflow window, select a trigger date you need to format [Triggered Date – 20-12-2023].

formatDateTime() Function Power Automate

4. The Power Automate formatDateTime() function will retrieve this output from the compose flow action like 20 December 2023.

 Use Power Automate formatDateTime() function

This is how to get the date in day, month name, and year format using a Power Automate formatDateTime() function.

Power Automate formatDateTime() in Day of the week, Month day, Year Format

Going deep into the Power Automate formatDateTime() function, let’s look at how to get the Day of the week, Month day, and Year Format.

Example

Suppose we begin with a timestamp of “2023-12-20”. For example, I wanted to get the timestamp in the day of the week, month day, and year Format. Then, my resulting timestamp will be “Wednesday, December 20, 2023,” as shown below.

Format a date in Power Automate using formatDateTime() expression

Follow the below-mentioned steps:

1. Take the Initialized variable flow action and set the value as given in the code below.

  • Name: Provide a name as a Date for the variable.
  • Type: Set data type as String from the drop-down
  • Value: Select the field -> Click Expression -> Give the below place code.
formatDateTime(utcNow(),'dddd,MMMM dd,yyyy')

Then, select OK.

How to Format a Date in Power Automate

2. Once the flow has been saved, select the desired date for the unit to be added in the “Run flow” window. Then, click Run flow.

formatDateTime() Function using  Power Automate

3. The image below illustrates the formatDateTime() function results, which gives the format of the provided timestamp.

  • The result will be like Wednesday, December 20, 2023.
Format a date in Power Automate using formatDateTime() function

This is how to use the Power Automate formatDateTime() function to get the date and time in the desired format.

Power Automate formatDateTime() in 12 Hours Time

In this section, look at an example that will get the timestamp with Month/day/year in 12 hours time format using a Power Automate addToTime() function.

Example:

Assuming a timestamp of “2023-12-20“, if we desire the timestamp in the format of MM/dd/yyyy with a 12-hour timezone format, the resulting timestamp would be “12/20/2023 12:00 AM“, as illustrated below.

Power Automate formatdatetime() in  12hours

To do this example, follow the below-given steps:

1. Set the expression in the code below in the value section of an initialized variable flow action.

  • Name: Provide a name as a Date for the variable.
  • Type: Set data type as String from the drop-down.
  • Value: Select the field -> Click Expression -> Give the below place code.
formatDateTime(triggerBody()['date'],'MM/dd/yyyy hh:mm tt')

Then, Click OK.

formatdatetime() timezone in Power Automate

2. The Power Automate formatDateTime() function will give the output relevant to the expression of a given timestamp in a defined format that can be seen in the compose flow action.

  • The triggered date is 2023-12-20, and the result is 12/20/2023 12:00 AM.
Power Automate formatdatetime() in  timezone

This is about the Power Automate formatDateTime() function to convert the timestamp into a customized format.

Power Automate formatDateTime() in 24 Hours Time

Let us see the final example, i.e., convert timestamp to 24-hour time zone by using a Power Automate formatDateTime() expression inside a flow.

Example

Just consider a timestamp of “2023-12-20” and require the timestamp to be formatted with a 24-hour timezone format; the resulting timestamp would be “20/12/2023 00:00:00 AM,” as shown below.

Power Automate formatdatetime() 24 hours

To do this example, follow the below-mentioned steps:

1. Similarly, change the format of formatDateTime() expression to include a 24hours format in the initialize variable. Provide the below-given details.

  • Name: Enter the name as a Date for the variable.
  • Type: Set data type as String from the drop-down.
  • Value: Select the field -> Click Expression -> Give the below place code.
formatDateTime(triggerBody()['date'],'dd/MM/yyyy HH:mm:ss tt')

Then, after the expression, Click OK.

Convert date time format to 24Hours in Power Automate

2.  The Power Automate formatDateTime() function will give the output in the compose flow action. Open the compose flow action to check the format.

  • The triggered date is 2023-12-20, and the return value from the formatDateTime will be 20/12/2023 00:00:00 AM.
Power Automate formatdatetime() in timezone

This is all about formatDateTime() expressions and how to use them in a Power Automate flow.

Conclusion

I trust you’ve gained insights into obtaining the current date or date and time in Power Automate in various formats. Additionally, you’ve learned how to provide different date and time formats using the formatDateTime() function in Power Automate.

Additionally, I have covered the topics on the Power Automate formatDateTime() function, such as:

  • Power Automate formatDateTime() Function
  • formatDateTime() Syntax format in Power Automate
  • Power Automate formatDateTime() function Formats
  • Power Automate formatDateTime() of UtcNow
  • Power Automate formatDateTime() in Year-Month-Date Format
  • Power Automate formatDateTime() of utcNow() with Time
  • Power Automate formatDateTime() of a Date Variable
  • Power Automate formatDateTime() in Day of the week, Month day, Year Format
  • Power Automate formatDateTime() in 12 Hours Time
  • Power Automate formatDateTime() in 24 Hours Time

Also, you may like some more Power Automate tutorials: