0

I am currently building something which OCRs dates which are written down without much structure/uniformity, i.e. they may be recorded as "Sat 5/8", "Saturday 05/08", "05/08/23", "5/8/2023", etc.

I would like to be able to process this as best as possible (i.e. if it is missing a year, assume that the year should be 2023/2024. so it is a proper Datetime type/object that I can put into a Dataverse column. Something like this exists in Python with dateutil.parser, I'm not sure what I can do similarly in Power Automate that might emulate this functionality short of sending the dates out over a HTTP request to a Python Azure Function or something, but I think this is probably overkill.

Thanks!

I haven't yet tried anything but perhaps there is a complicated regex or something I could use? Not sure!

  • Re: my answer, when it comes to running the flow and determining which one to execute, I'd suggest (and this is untested) trying to run them all (i.e. all of the conversion types) as, by the sounds of it, it will be sure to work for one of them. You'd just need to structure your flow to continue on error for all of the steps that fail. Alternatively, if you wanted to do it in something like C# with try/catch statements, I can provide an answer for you on that as well. It'd mean a single operation step that does the work. – Skin Aug 04 '23 at 02:02

1 Answers1

0

Yes, it's very much possible. Obviously though, the system will default missing components of the date where it needs to.

You can use the parseDateTime function within an expression ... https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#parsedatetime

enter image description here

Some examples for you (take note you need to change out en-AU for your preferred region) ...

Sat 5/8

parseDateTime('Sat 5/8', 'en-AU', 'ddd d/M')

Saturday 05/08

parseDateTime('Saturday 05/08', 'en-AU', 'dddd dd/MM')

05/08/23

parseDateTime('05/08/23', 'en-AU', 'dd/MM/yy')

5/8/2023

parseDateTime('5/8/2023', 'en-AU', 'M/d/yyyy')

... and my suggestion for wanting to know how to construct the format string, just use Excel documentation ...

https://support.microsoft.com/en-au/office/format-a-date-the-way-you-want-8e10019e-d5d8-47a1-ba95-db95123d273e

Then on the tail end of that, you can use formatDateTime to have it represented in the exact format you require.

https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#formatdatetime

Skin
  • 9,085
  • 2
  • 13
  • 29