Power Automate’s formatdatetime: Your Ultimate Guide

microsoft-365-MFK0JpFU13U-unsplash
Power Automate Power Platform

Power Automate’s formatdatetime: Your Ultimate Guide

In an increasingly digitized world where automation and efficiency reign supreme, Microsoft’s Power Automate stands tall as a beacon of productivity enhancement. In this context, the Power Automate formatDateTime function plays a crucial role. Whether it’s managing the Power Automate date format, adjusting time specifications, or working with variables.

This versatile feature offers immense potential to users. However, understanding this function is not always straightforward, and hence the present article is necessary. This comprehensive guide aims to demystify the intricacies of formatDateTime, diving deep into its applications, and provide basic Power Automate training for this function.

Such as setting the Power Automate formatDateTime current date, manipulating Power automate date format and time formats, and managing Power Automate formatDateTime ISO 8601 standards. We’ll explore utilizing Power Automate formatDateTime with variables, implementing different date styles like “MM/dd/yyyy”, and managing time settings in AM/PM.

Moreover, we’ll clarify the specific application of Power automate formatDateTime date only parameters. Whether you’re a seasoned user or a beginner in Power Automate, this article will be your trusted companion in navigating the intriguing world of the formatDateTime function.

Understanding Power Automate date and time

A core component of Power Automate is its ability to handle and manipulate Power Automate Date and Time data effectively. At the heart of this functionality is the formatDateTime function, which comes loaded with diverse capabilities that enable users to tailor their Power Automate date and time outputs according to their needs. One feature that sets the formatDateTime function apart is its flexibility in presenting time data.

Whether you prefer a 24-hour clock or localized time, the function is capable of both. By using the formatDateTime function, you can easily change the time format to a 24-hour scale by implementing the ‘HH:mm:ss’ pattern. Likewise, you can employ the utcNow() function to display Power Automate formatDateTime Local Time, and adapt it to your specific Power Automate formatDateTime TimeZone using the ConvertTimeZone function.

Furthermore, the Power automate formatDateTime function allows users to display the date in multiple ways. For instance, you can represent Power Automate formatDateTime date as number or even as the day of the week using the ‘dd’ and ‘dddd’ format strings, respectively. Power Automate formatDateTime also supports formatting Power Automate formatDateTime Null dates, which can be particularly useful in scenarios where date data might be absent or not applicable.

Moreover, the function offers an easy way to handle data and time across different time zones, a feature that becomes vital when working with geographically dispersed teams or datasets. Users can effortlessly manage and convert time zone data by applying the ‘z’ or ‘zzz’ format strings. Customization remains a powerful aspect of Power Automate formatDateTime Date & Time, extending to the representation of date data.

Read also: Power Automate Substring Function: Explanation, Examples, Best Practices

Whether you need a Power Automate formatDateTime Long date, a Power Automate formatDateTime Short Date, or even the current day of the week, formatDateTime can cater to your needs. You can apply ‘D’ for long date patterns and ‘d’ for short ones. Additionally, it’s worth noting that manipulating dates, such as adding or subtracting days, is a breeze with the ‘addDays()’ and ‘subDays()’ functions, respectively.

Integrating the FormatDateTime function in a Flow is relatively simple in terms of practical application. This incorporation allows for seamless date and time formatting in your automated processes, thereby enhancing efficiency and data presentation.

To summarize, understanding and effectively using the Power Automate formatDateTime function is a game-changer in the realm of Power Automate date and time manipulation. Its impressive suite of features empowers users to customize date and time values according to their specific requirements, thus bringing automation one step closer to perfection.

How to use Power Automate formatDateTime function

The formatDateTime function in Power Automate is a powerful tool for manipulating and formatting date and time data. It converts Power Automate date and time strings into various display formats. To make your automated flows more flexible and data-friendly.

To use the formatDateTime function, you first need to understand its syntax. It requires two arguments: a date or time and a format string. The date or time is typically provided in a string format, while the format string specifies the output format for the Power Automate date and time.

Here’s an example of the basic usage of the Power Automate formatDateTime Date & Time function in Power Automate:

formatDateTime(utcnow(), ‘yyyy-MM-dd’)

Example of Power Automate formatDateTime

In this case, utcnow() is used to get the Power Automate formatDateTime current date and time in the Coordinated Universal Time (UTC). The format string ‘yyyy-MM-dd’ tells the function to format this date into the year-month-day format. The output will be the current date in the format ‘2023-06-01’, if today were June 1, 2023.

You can change the format string if you wish to use a different Power automate date format. For instance, if you want to get the current date and time in the format ‘yyyy mm dd-hh mm ss’, you can use the following code:

formatDateTime(utcnow(), ‘yyyy MM dd-HH mm ss’)

get the current date and time in the format 'yyyy mm dd-hh mm ss'

On the other hand, if you want to format a date in Power Automate, you need to employ the ‘toLocaleString()’ method with the desired locale and options. Unfortunately, as of my knowledge cutoff in September 2021, Power Automate formatDateTime function doesn’t directly support different languages.

You can use the Power Automate parseDateTime function if you have a string that represents a date and time and you want to convert it into a valid Power automate date format. For example, suppose you have the string ‘20230601’. In that case, you can use the parseDateTime function to convert it into a date:

formatDateTime(parseDateTime(‘20230601’, ‘yyyyMMdd’), ‘yyyy-MM-dd’)

use the parseDateTime function to convert it into a date

Here, the ‘yyyyMMdd’ format string is used to interpret the date in the string, and the Power automate formatDateTime function is then used to format this date in the ‘yyyy-MM-dd’ format.

Formatting date & time in Power Automate

Step 1: Open Power Automate

First, log into the Power Automate website at flow.microsoft.com, and go to ‘My flows’ if you want to edit an existing flow. Or you can create a new flow by clicking ‘Create’ from the left-hand menu.

log into the Power Automate website

Step 2: Create a Variable

Power Automate formatDateTime Add days an Initialize Variable action to your flow. You must set the variable’s name, type, and value. For instance, you can create a variable named currentDate of type ‘String’ and set the value to utcNow(). This will store the Power Automate formatDateTime current date and time in UTC format.

Create a Variable

Step 3: Format the Variable

You must format the variable using the formatDateTime function. Add a ‘Set variable’ action and choose the currentDate variable. For the value, use the Power automate formatDateTime function to format the date. Here’s how you can use it:

To format the date in ISO 8601 format, the value should be:

formatDateTime(variables(‘currentDate’), ‘yyyy-MM-ddTHH:mm:ssZ’)

Format the Variable

To format the date in Power Automate formatDateTime “MM/dd/yyyy” format, the value should be:

formatDateTime(variables(‘currentDate’), ‘MM/dd/yyyy’)

format the date in Power Automate formatDateTime "MM/dd/yyyy"

To format the time in Power Automate formatDateTime 24 hours format, the value should be:

formatDateTime(variables(‘currentDate’), ‘HH:mm’)

formatDateTime 24 hours format

To format the time in AM/PM format, the value should be:

formatDateTime(variables(‘currentDate’), ‘hh:mm tt’)

format the time in AM/PM format

To format the date as a number, the value should be:

formatDateTime(variables(‘currentDate’), ‘yyyyMMdd’)

format the date as a number in Power Automate

Step 4: Use the Formatted Variable

You can now use the currentDate variable in your flow. And it will have the date and time formatted according to the Power automate formatDateTime function.

Use the Formatted Variable

Step 5: Save and Test

After setting up the date and time formatting, you can save your flow and test it to see if it’s working as expected.

Save and Test your Power Automate flow

Recommended reading: How to Use Power Automate Filter Query

Working with current date in Power Automate

Power Automate (formerly Microsoft Flow) is a tool that allows users to automate repetitive tasks without the need for coding knowledge. You can use various actions, functions, and expressions to work with the current date in Power Automate.

Follow the steps below to create a simple flow that will work with the current date:

Step 1. Sign in to Power Automate using your Microsoft account.

Step 2. From the left-hand menu, select ‘My flows’, then ‘New’, and finally ‘Automated from blank’.

Working with Current Date in Power Automate

Step 3. Provide a name for your flow in the ‘Flow name’ field and select the trigger for your flow. For this example, we will use the trigger ‘When a new email arrives (V3)’ (Office 365 Outlook). Click on ‘Create’.

Provide a name for your flow in the 'Flow name'

Step 4. In the new trigger that appears, you can leave the Inbox as the default Folder or select a different one from the drop-down menu.

choose the option from the drop-down menu

Read also: Power Automate Trigger Conditions: Example-Based Guide

Step 5. Now, let’s add an action that will use the current date. Click on ‘+ New Step’. In the ‘Choose an action’ box, select ‘Compose’ (Data Operation).

add an action that will use the current date

Step 6. Click into the ‘Inputs’ field of the ‘Compose’ action.

Here you have a few options to get the current date:

  • If you want just the date without the time, you can enter the following expression: formatDateTime(utcNow(),’yyyy-MM-dd’).
  • If you want the date with the time, you can use this expression: utcNow().

To enter the expression, click on the ‘Expression’ tab, type the desire expression in, and press ‘OK’.

Click into the 'Inputs' field of the 'Compose' action

Step 7. Your flow is now ready to use the current date. You can continue to add steps that will use this data.

Remember to save your flow by clicking on ‘Save’ in the top-right corner.

save your flow in power automate

Read also: Sending Emails with Power Automate Step-by-Step

Using Power Automate formatDateTime variables

In Power Automate, you can use the Power automate formatDateTime function to change the format of dates and times. This function takes two arguments. The date you want to format and a string representing the desired format.

Below is a step-by-step guide to using Power Automate formatDateTime Variable with the Power automate formatDateTime function.

Step 1: Create a new Flow

Open Power Automate and create a new Flow (Automated, Instant, or Scheduled, depending on your needs).

Create a new power automate Flow

Step 2: Initialize Variable

Add a ‘Initialize Variable’ action.

Initialize Variable in power automate

Step 3: You can name the variable as “CurrentDate” (or any name you prefer), select ‘String’ as the Type, and set the Value to utcNow(). This will store the current date and time in the variable.

store the current date and time in the variable

Step 4: Format the Date/Time Variable

Add a ‘Compose’ action to format the variable. In the Inputs field, use the Power automate formatDateTime function with the variable and the desired date/time format. Below are some examples of different formats you need to choose any that you like more:

  • For a MM/dd/yyyy format, use: formatDateTime(variables(‘CurrentDate’), ‘MM/dd/yyyy’).
  • For AM/PM format, use: formatDateTime(variables(‘CurrentDate’), ‘hh:mm tt’).
  • For ISO 8601 format, use: formatDateTime(variables(‘CurrentDate’), ‘yyyy-MM-ddTHH:mm:ssZ’).
  • For a 24 hours format, use: formatDateTime(variables(‘CurrentDate’), ‘HH:mm’).
  • To format date as a number, use: formatDateTime(variables(‘CurrentDate’), ‘yyyyMMdd’).

The result of this compose action will be the date and/or time formatted as per your requirement.

date and/or time is formatted as per your requirement

Step 5: Use the Formatted Date/Time

You can now use the output of the compose action wherever required in your Flow.

Step 5: Use the Formatted Date/Time

Remember, Power Automate uses the format strings in accordance with the .NET custom date and time formatting conventions. So, you can customize the format as you need, following those guidelines.

Read also: Understanding Power Automate Compose

Formatting date only in Power Automate

Microsoft’s Power Automate, formerly known as Flow, has a variety of functions you can use within expressions. The Power automate formatDateTime function is one of them, and it’s great for manipulating and formatting date and time values.

Let’s say you have a DateTime variable and want to format it to display the Power Automate formatDateTime date only, ignoring the time part. Here are the steps you need to follow:

1. Start your flow

Depending on your needs, you could start your flow manually, automatically, or from a template.

Start your flow in power automate

2. Add a new step

Click on + New step to add an action.

Add a new step

3. Choose an action

For this step, choose Compose from the Data Operation action group. This action is often used to manipulate or calculate data, and that’s exactly what you’re doing here.

Choose an action

4. Create your expression

Inside the Inputs field of the Compose action, click on the Expression tab on the right side of the Dynamic content window.

Create your expression

5. Write your expression

Here, you’ll use the Power automate formatDateTime function to format your date. Let’s say your DateTime variable is named yourDateTimeVariable. Then your expression should look like this:

formatDateTime(variables(‘yourDateTimeVariable’), ‘yyyy-MM-dd’).

Write your expression

This will return the date in the format of “Year-Month-Day” (for example, “2023-06-02”).

6. Click OK

Once you’ve entered your expression, click OK to close the expression window.

7. Save your flow

Finally, click on Save in the top-right corner to save your flow.

Save your flow in power automate

Further reading: Power Automate Functions Overview

Formatting time in AM/PM in Power Automate

To format time in Power Automate formatDateTime AM/PM (formerly known as Microsoft Flow), you can use expressions. Here is a step-by-step guide:

1. Select your flow

Navigate to the flow where you want to format the time. Here I am going with a Manual trigger.

Formatting time in AM/PM in Power Automate

2. Add an action

Click “+ New step” and select “Compose” under “Data Operation” from the Actions list.

select "Compose" under "Data Operation"

3. Use an expression to format the time

In the “Compose” action, you would use the “formatDateTime()” function. You’ll use an expression like this in the “Inputs” box:

formatDateTime(utcNow(),’hh:mm tt’)

Use an expression to format the time

This will format the current UTC time in a 12-hour format with Power Automate formatDateTime AM/PM. If you want to format a specific time, replace utcNow() with your timestamp.

4. Save your flow

Make sure to save your changes to your flow.

This will change the 24-hour time format into a 12-hour time format with AM/PM. Please note that Power Automate uses a case-sensitive workflow definition language (WDL) to run its functions and actions, so you’ll need to make sure you’re typing everything in the correct case.

Further reading: How to Populate a Word Document with Power Automate?

Common errors with the formatDateTime function in Power Automate

The Power automate formatDateTime function is a useful tool in Power Automate (formerly known as Microsoft Flow) for converting timestamps to different formats. However, users can encounter various errors while using this function, especially if unfamiliar with its syntax and usage. Here are some of the most common errors:

  1. Incorrect Power Automate Date Format: The Power automate formatDateTime function expects the date in a specific format (ISO 8601 – “yyyy-MM-ddTHH:mm:ssZ”). If the date isn’t in this format, the function will fail. This often occurs when users enter dates from custom fields or other data sources.
  2. Incorrect Format Strings: The Power automate formatDateTime function uses the .NET format strings for date and time. The function will fail if an incorrect or unsupported format string is used. You must ensure you use the correct format strings for your date and time.
  3. Null or Empty Values: If the date to be formatted is Power Automate formatDateTime Null or empty, the function will throw an error. It’s a good practice to check whether the date is null or empty before calling the Power automate formatDateTime function.
  4. Time Zone Issues: Power Automate uses Coordinated Universal Time (UTC) by default. If you’re dealing with different time zones, you might face some inconsistencies if you do not convert the time to the correct zone.
  5. Incorrect Syntax: The Power automate formatDateTime function syntax must be correct, or it will cause an error. The proper syntax is formatDateTime(timestamp, format), where timestamp is the date and time you want to format, and format is the format string.
  6. Trouble with Leap Years or DST: Sometimes, Power automate formatDateTime may incorrectly handle dates from leap years or Daylight Saving Time periods. Be aware of these potential inconsistencies, especially when dealing with historical data.

To avoid these errors, it’s recommended to:

  • Always verify your date data before attempting to use it with formatDateTime.
  • Understand and correctly implement the format strings used by the .NET framework.
  • Be mindful of the time zone your data is in and how it may need to be converted.
  • Use error handling practices to capture and manage any potential errors with the formatDateTime function.

Conclusion

Understanding and effectively using the Power Automate formatDateTime function in Power Automate is integral to managing date and time data in your workflows, and an important part of Power Automate training. From formatting the current date to manipulating DateTime variables, the function provides flexibility and control over date and time formatting. Whether you want to display dates in ISO 8601 format, “MM/dd/yyyy” format, long date or short date format.

Or even adapt to AM/PM or 24-hour time, Power Automate formatDateTime has you covered. It’s equally useful for customizing date and time values, adding or Power Automate formatDateTime Subtract Days, and even handling null values or converting times between time zones.

Understanding the nuances of Power Automate’s date format can help you avoid common errors and ensure your workflows operate seamlessly. As you explore the Power automate formatDateTime function further, you will find it to be an indispensable tool in your Power Automate toolkit, aiding you in maintaining your data’s consistency and reliability, irrespective of its complexity.

As you can see from our article, with enough training, Power Automate will be a great tool in your work, both for people with technical background, and for those who recently changed their career and are new to the platform.

Frequently Asked Questions

What is the formatdatetime function in Power Automate?

The Power Automate formatDateTime function in Power Automate is a tool used to convert and Power Automate format date and time values. This function expects the date and time in a specific format (Power Automate formatDateTime ISO 8601  - "yyyy-MM-ddTHH:mm:ssZ") and outputs it in the .NET format specified by the user.

How to use the formatdatetime function in Power Automate?

To use the Power automate formatDateTime function in Power Automate, you need to follow the syntax formatDateTime(timestamp, format). 'timestamp' refers to the date and time you want to format, and 'format' refers to the format string you want the timestamp to be converted into.

How to Power Automate format date and time in Power Automate?

To Power Automate format date and time in Power Automate, you can use the Power automate formatDateTime function. You'll need to pass in the timestamp that you want to format and the format string you want to use. Here's an example: formatDateTime(variables('YourDateTimeVariable'), 'dd-MM-yyyy HH:mm:ss') In this example, 'YourDateTimeVariable' is the date and time that you want to format, and 'dd-MM-yyyy HH:mm:ss' is the format string.

How to format current date in Power Automate?

To format the current date in Power Automate, you can use the utcNow() function with the Power Automate formatDateTime function. Here's an example: formatDateTime(utcNow(), 'dd/MM/yyyy') In this example, utcNow() will return the current date and time in UTC, and the Power automate formatDateTime function will format it into 'dd/MM/yyyy' format.

How to format DateTime variable in Power Automate?

You can format a DateTime variable in Power Automate using the Power Automate formatDateTime function. Here's an example: formatDateTime(variables('YourDateTimeVariable'), 'MM-dd-yyyy') In this example, 'YourDateTimeVariable' is the DateTime variable that you want to format, and 'MM-dd-yyyy' is the format string.

How to format DateTime in “MM/dd/yyyy” format in Power Automate?

You can format DateTime in “MM/dd/yyyy” format in Power Automate using the formatDateTime function. Here's an example: formatDateTime(variables('YourDateTimeVariable'), 'MM/dd/yyyy') In this example, 'YourDateTimeVariable' is the DateTime variable that you want to format, and 'MM/dd/yyyy' is the format string.

Comment (1)

  1. Tamara

    Thanks a lot for sharing! This is exactly what I needed!

Leave your thought here

Your email address will not be published. Required fields are marked *