How to Convert String to Date in Power Automate?

Do you want to convert the string to date in Power Automate? In this Power Automate tutorial, we will see how to convert string to date in Power Automate.

In Power Automate, there can be data that appears to be a date but is actually just regular text.

If you want to perform like changing the date’s format or adding more days to it, you have to change that string into a proper date format that Power Automate can understand. Otherwise, you will come across the below error after running the flow.

string to date Power Automate

Here, we will cover the topics below

  • How to convert string to date in Power Automate.
  • How to convert string to date using the ParseDateTime function in Power Automate

Let’s see how to convert string to date in Power Automate. The string will formatted to the proper date format i.e., ISO 8601 format.

Convert string to date in Power Automate

Here, we will see how to convert a string to date in Power Automate.

We will take a date string and we will convert that string to date format, which satisfies ISO 8601 format.

To do this in Power Automate, follow the below steps:

1. Open Power Automate Cloud, then click on +Create -> select Instant Cloud Flow.

convert string to date in Microsoft Power Automate

Then, provide a flow name and select Manually trigger a flow action. Then click on Create.

string to date in Power Automate

Now, you can see the “Manually trigger a flow” action is added to the flow page in Power Automate.

convert string to date in Power Automate

2. We will initialize a string variable; for this, click on +New step -> select Initialize variable action. Then provide the below information:

  • Name: Provide the name of the variable
  • Type: Provide the type as a string
  • Value: Provide the value like below
How to convert string to date in Microsoft Power Automate

3. We will split the string to get the date; for this, click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the below expression.
split(split(variables('str'),' ')[0],'/')
How to convert string to date in Power Automate

4. Now, we will create a date; for this, click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the below expression:
join(reverse(outputs('Compose')),'-')
Convert string to date Power Automate

5. Now save and run the flow manually; you can see the string is converted to date in Power Automate.

string to date Microsoft Power Automate

This is how to convert string to date in Power Automate.

Convert string to date using ParseDateTime function in Power Automate

Here, we will see how to convert string to date using the ParseDateTime() function in Power Automate.

The parseDateTime() function in Power Automate will take the date string and convert it into date format i.e., ISO 8601 format.

Syntax:

parseDateTime(<timestamp>, <locale>, <format>)

In the above syntax:

  • timestamp: is the date string that needs to be parsed
  • Locale: the locale of the provided date
  • format: the format of the provided date.

Now, let’s see an example of how to convert string to date using Power Automate.

1. Open Power Automate Cloud, then click on +Create -> select Instant Cloud Flow.

Power Automate flow convert string to date

Then, provide a flow name and select Manually trigger a flow action. Then click on Create.

string to date in Power Automate

Now, you can see the “Manually trigger a flow” action is added to the flow page in Power Automate.

convert string to date in Power Automate

2. We will initialize a string variable; for this, click on +New step -> select Initialize variable action. Then provide the below information:

  • Name: Provide the name of the variable
  • Type: Provide the type as a string
  • Value: Provide the value like below
Microsoft Power Automate string to date

3. We will convert the given string to date format using the parseDateTime() function in Power Automate. For this, click on the +new step and select Compose action. Then provide the below information:

  • Inputs: Provide the below expression:
parseDateTime(variables('str'),'en-US','yyyy-MM-dd hh:mm tt')
Power Automate string to date

4. Now save the flow and run the flow manually; you can see the string is converted to date in Power Automate.

Power Automate convert string to date

This is how to convert string to date using parseDateTime in Power Automate.

Conclusion

In this Power Automate tutorial, we saw how to convert string to date in Power Automate. Also, I have explained how to convert string to date using ParseDateTime() function in Power Automate.

You may also like:

>