Text to date with custom format

  

Hi everybody!

I'm building this app in which I get dates in several formats. In the web app I don't mind being stuck with whatever is selected in Service Center (YYYY-MM-DD currently) but I have to import excels and consume APIs from several places and I have no guarantee on dates data quality meaning that from one integration they can be in the format of YYYY-MM-DD or DD/MM/YYYY or even YYYY-DD-MM .

Is there any function that given a date in this format plus the format template it returns a date? If there is I haven't found it   

The only solution I'm seeing is to split the string and create a new date with the parts returned from split.


Any idea?

Hi,


There is no builtin that lets you pick a format for parsing (and did a quick search in forge and didn't find anything). While the "TextToDatetime" is a bit more permissive than what the documentation actually says, it is is not able to distinguish the cases that are ambiguous.

In your integrations are you always able to know in what format it will be? (Specially since you mentioned YDM format that is not a usual format used anywhere)


Regards,

João Rosado

Hi João!

Answering your question directly: yes. We are integrating with 3 web services and also parsing an excel file.

For each web service and for the excel file we know the format. So I can configure that service A uses YYYY-MM-DD, service B uses DD/MM/YYYY, C uses YYYY-DD-MM and excel uses DD-MM-YYYY .

Hi Miguel,


Just did a little extension to do that. Can you try it and see if it solves your needs?

It just wraps the .Net DateTime.TryParseExact method, so you can check the format options here.


Regards,

João Rosado


Hi João!

Sorry for answering so late :(

When you told me there was no way to do that I started an extension as well, published as "AdditionalTextUtils".

Thanks for the help!

João Rosado wrote:

Hi Miguel,


Just did a little extension to do that. Can you try it and see if it solves your needs?

It just wraps the .Net DateTime.TryParseExact method, so you can check the format options here.


Regards,

João Rosado



Great job Joao!! Great great extension! work like a charm! :)

Thank you a lot! 

OS should think include this tool by default on the next release.


Cheers