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.
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.
Then, provide a flow name and select Manually trigger a flow action. Then click on Create.
Now, you can see the “Manually trigger a flow” action is added to the flow page 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
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],'/')
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')),'-')
5. Now save and run the flow manually; you can see the string is converted to date in 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.
Then, provide a flow name and select Manually trigger a flow action. Then click on Create.
Now, you can see the “Manually trigger a flow” action is added to the flow page 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
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')
4. Now save the flow and run the flow manually; you can see the string is converted to date in Power Automate.
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:
- How to Convert String to Decimal in Power Automate?
- Convert String to Object in Power Automate
- Convert a String to an Array in Power Automate
- Convert String to Integer in 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