Are you getting the unexpected format of date and time as you expected in a Power Automate Flow? And you need to format the date and time to get what you expected. Here, I will show you how to work with formatdatetime in Power Automate with real examples.
I will show you the following:
- Power Automate formatdatetime() function with syntax.
- How to use formatdatetime function in Power Automate to format date time in Power Automate.
- How to work with utcNow() format in Power Automate.
- List of formats available to use in formatdatetime function in Power Automate
formatdatetime in Power Automate
The formatdatetime function in Power Automate allows you to customize how date and time values are displayed inside a flow.
With the help of this function, you may provide a specific format that will be used to display date and time information regardless of the user’s locale or system preferences. This function returns the date and time in string format.
Let’s first see an example of how a date and time value looks in Power Automate without formatting.
In this Power Automate flow, we first initialize the variable “standarddatetime” and we set the current timestamp utcNow() as value for the variable “standarddatetime” and pass the same to the email body
Without any formatting, the email will look something like this, and it is not in the standard format; also, it is hard to read.
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 to format date and time values in a flow in Power Automate using some examples.
formatdatetime() in Power Automate Syntax
Here is the formatdatetime() in Power Automate syntax.
In this syntax
- Timestamp: It is the date and time you want to convert to the required format.
- Format: It is the desired format of date and time
Example: I have a timestamp i.e. ‘2023-10-25T13:56:02Z’, and I need to format it to ‘dd-MM-yyyy’, so the result will be 25-10-2023.
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 use the format style ‘dd/MM/yyyy hh:mm tt‘ in the above function.
So, we are 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 the date and time output.
This is how to format date time in Power Automate. Let’s see more such examples of format date time in Power Automate.
How to use formatdatetime function in Power Automate
Here we will see how to use the formatdatetime function in Power Automate with a few examples.
Example 1. Format utcNow() in ‘yyyy-MM-dd’
To get the current date time we will use the function utcNow() which will return today’s date time in ISO 8601 format. Then we will format it to yyyy-MM-dd using formatdate time.
Now let’s see how we can do it in Power Automate.
1. Open Power Automate Cloud, click on +Create select Instant Cloud flow.
Then provide the flow name -> select Manually trigger a flow. Then click on Create.
Now you can see the “Manually trigger a flow” flow action is added to the flow page.
2. We will initialize a variable that will store the current date and time. For this, click on the +New step -> select Initialize variable action.
Provide the below information:
- Name: Provide the variable name
- Type: Provide the type as string
- Value: Provide the below expression
3. Now we will format the current date time to ‘yyyy-MM-dd’, for this click on the +New step -> select compose action. Then Provide the below information.
Inputs: Provide the below expression:
4. Now run the flow manually and you can see the current date time is converted to the required format in Power Automate.
Example 2: Format date time to ‘yyyy-MM-dd hh:mm tt’
I have a date and time i.e. ‘2023-10-20T14:56:02Z’ and I need to convert it to this format ‘yyyy-MM-dd hh:mm tt’ in Power Automate. The output will be 2023-10-20 02:56 PM
To do this in the above flow in Power Automate. In the Initialize variable action, provide the date and time in the value field.
Then, in the compose action, provide the below expression in the Inputs field, like the below screenshot.
formatDateTime(variables('currdDateTime'),'yyyy-MM-dd hh:mm tt')
Now run the flow manually and you can see the date and time are formatted in Power Automate.
Example 3: Power Automate format date dd/mm/yyyy
Let us see one example of “Power Automate format date dd/mm/yyyy”.
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 we created in the above example and setting the current date value in ‘dd/MM/yyyy‘ format.
Here is the expression:
After applying the format style of “dd/MM/yyyy“, we will receive the date and time value as 06/07/2024 in the email.
So, whenever date-only formatting is required in Power Automate, we will simply pass the format style ”dd/MM/yyyy to the function.
Example 4: 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.
Here is the expression:
After applying the above formatting style, we received the below email with the formatted date as 09/06/2024
and that’s how to format the date in “MM/dd/yyyy” style in Power Automate.
This is how to use the formatDateTime() in Power Automate to format the date.
utcNow() format in Power Automate
Here we will how to format utcNow() in Power Automate.
The utcNow() function is similar to Now()or Today(), which returns the current date time in UTC. The function utcNow() returns the current DateTime in the format of “yyyy-MM-ddTHH:mm:ssZ”. You will find the utcNow() function under the “Expression Tab” when adding data to input in Power Automate.
Example utcNow(yyyy-MM-dd) , it return ‘2023-10-26’
If you do not pass any format then it will return with the default format ‘yyyy-MM-ddTHH:mm:ssZ’, e.g. ‘2023-08-11T14:21:05.2031122Z’
Also, we can formatDateTime() and pass the utcNow() and provide the format to format the current date and time.
Now let’s see with an example how we can format the utcNow.
For example, we will convert the UtcNow() to ‘dddd, yyyy-MMM HH:mm tt’, and the result will be ‘Thursday, 2023-Oct 07:04 AM’
1. Open Power Automate Cloud, then click on +Create -> select Instant Cloud Flow.
Then provide a flow name and select Manually trigger a flow action. Then click on Create.
Now, you can see a manual trigger a flow action is added to the flow page.
2. Now we will format the utcNow, for this, click on the Compose action and then provide the below information:
- Inputs: Provide the below expression
formatDateTime(utcNow(),'dddd, yyyy-MMM HH:mm tt')
utcNow('dddd, yyyy-MMM HH:mm tt')
3. Now save and run the flow manually and you can see the date and time are formatted to the desired format.
List of Power Automate datetime format in formatDateTime function
Here we will see some of the formats that we can use to formatDateTime functions in Power Automate.
List of Formats for format DateTime in Power Automate
|yy||year last 2 digit||23|
|MMM||Month in short||Oct|
|MMMM||Month in long||October|
|ddd||Day of week in short||Fri|
|dddd||Day of week in long||Friday|
|‘yyyy-MM-dd’||year month day||2023-10-28|
|dd-MM-yyyy||day month year||28-10-2023|
|dd-MMMM-yyyy||day- long month- year||28-October-2023|
|dddd, dd-MMMM, yyyy||day of week, day-Long Month, year||Friday, 28-October-2023|
|yyyy-MM-ddTHH:mm:ssZ||IS0 8601 format in power automate||2023-10-20T14:56:02Z|
|HH||24 hr format||14-> 2 PM|
|hh||12 hr format||02-> 2 PM|
|HH:mm tt||Hour:minute AM/PM||2:56 PM|
|g||General date time format of short time||10/20/2023 2:56 PM|
|d||General date format of short date||10/20/2023|
These are the list of formats you can use in formatDateTime() in Power Automate.
I hope from these real examples, you know now how to format date time in Power Automate. I have explained how to use the formatdatetime() in Power Automate. Also, we checked the list of Power Automate date formats available in the Power Automate formatdatetime() function. We also covered the below examples:
- utcnow() format in Power Automate
- Power Automate date format dd/mm/yyyy
- formatdatetime(utcnow() ‘yyyy-mm-dd’)
You may also like:
- How to Format Number without Decimal in Power Automate?
- Format Number Thousand Separator in Power Automate
- format number in Power Automate
- Format Numbers to Decimal Places Using Power Automate
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com