Skip to main content

Notifications

Community site session details

Community site session details

Session Id : XcKdTbmKHd8BywCnT2RyHU
Power Automate - Power Automate Desktop
Answered

Convert text to datetime - custom format

Like (0) ShareShare
ReportReport
Posted on 28 Mar 2022 18:27:31 by 15

I'm trying to convert text to a datetime field for a date comparison however I keep getting this error "The provided text value can't be converted into a valid datetime."  I've posted my Subflow text below.

 

I'm getting a date from a web browser SSL certificate(The Valid From and Valid To fields on the certificate) and this is the format I'm grabbing.

 

Wednesday, ‎October ‎19, ‎2022 3:49:37 PM

 

When I try to convert it to a datetime field using a custom format(dddd, MMMM dd, yyyy hh:mm:ss tt) I'm getting errors.  I've tried all sorts of things to get this to work but haven't been able to do so.    At one point I just tried hard coding the date so I wasn't messing around with variables and I swear I had it working with the hard coded value.  However when I try to do it again, I'm not having any luck.  Really stumped on this one.

 

FUNCTION Subflow_1 GLOBAL
SET NewVar TO $'''‎Wednesday, ‎October ‎19, ‎2022 3:49:37 PM'''
Text.ConvertTextToDateTime.ToDateTimeCustomFormat Text: NewVar CustomFormat: $'''dddd, MMMM dd, yyyy hh:mm:ss tt''' DateTime=> TextAsDateTime
Display.ShowMessageDialog.ShowMessage Title: $'''Converted Date''' Message: TextAsDateTime Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
END FUNCTION

  • VJR Profile Picture
    7,635 on 30 Mar 2022 at 12:09:51
    Re: Convert text to datetime - custom format

    Its working for me too now 🙂

    You can close the thread if you are all set with the post.

  • RealPabloBlanco Profile Picture
    15 on 30 Mar 2022 at 11:56:01
    Re: Convert text to datetime - custom format

    Thanks for the response, but I solved the issue by removing the unicode characters.   I tested your issue above with the date format 29/03/2022 and had no issues.  I'm guessing you have unicode or some other non-ascii characters in your text as well.    I created the single action below and it ran without issue.

     

    RealPabloBlanco_0-1648641334105.png

     

  • VJR Profile Picture
    7,635 on 30 Mar 2022 at 02:49:24
    Re: Convert text to datetime - custom format

    Hi @RealPabloBlanco 

     

    It could be in your case that the issue is due to some characters that you just mentioned. But this is not always the case, because, as I mentioned above, even a simple text like 29/03/2022 in the Convert text to Datetime is giving the same error as yours.

     

    Anyways lets look at your problem. What kind of characters are you seeing and want them to be removed via PAD?

    Do share some screenshots, written text, etc.

  • Verified answer
    RealPabloBlanco Profile Picture
    15 on 29 Mar 2022 at 12:21:54
    Re: Convert text to datetime - custom format

    I think I figured out the issue and wanted to follow up and share in case anyone comes across this.  I was going to write my own parser via Regex to fix this.  I went to a site(https://regex101.com/) and pasted my string in there and noticed I had unicode characters in there.  When I removed the unicode characters everything worked fine.   I just need to figure out how to strip off the unicode characters in my real script now.

  • VJR Profile Picture
    7,635 on 29 Mar 2022 at 12:11:59
    Re: Convert text to datetime - custom format

    A simple date of 29/03/2022 and format of dd/MM/yyyy in the Convert text to Datetime is not working.

    Looks like a bug.

  • RealPabloBlanco Profile Picture
    15 on 29 Mar 2022 at 12:02:40
    Re: Convert text to datetime - custom format

    The strange thing is, if I get the current date/time, and convert that to the format using 'dddd, MMMM dd, yyyy h:mm:ss tt' and then take that string and convert it back to a DateTime it works.  Anytime I try to put in my own string though I get an error.

  • RealPabloBlanco Profile Picture
    15 on 29 Mar 2022 at 11:58:50
    Re: Convert text to datetime - custom format

    Still no luck with that.   I created a super simple 1 step flow and cannot get this date format to pull in.  Very frustrating.

     

    RealPabloBlanco_0-1648555047774.png

     

  • MichaelAnnis Profile Picture
    5,721 Super User 2025 Season 1 on 28 Mar 2022 at 20:21:09
    Re: Convert text to datetime - custom format

    Try just one “h” for the hours, because there is no “0” in front of your 3.  

    best of luck!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Power Automate Desktop

#1
eetuRobo Profile Picture

eetuRobo 11 Super User 2025 Season 1

#2
KO-05050229-0 Profile Picture

KO-05050229-0 4

#2
John_Mavridis Profile Picture

John_Mavridis 4 Microsoft Employee

Overall leaderboard