ParseDate vs. DateTime.FromString

Any advices how to increase the performance of DateTime.FromString?
I compared the old ParseDate to the new DateTime.FromString function.
Unfortunately the new one is about 300 times slower than the old one.

Demo project:
https://drive.google.com/file/d/1PaqDzZcTYnLjyKdeKVgL4kGXLKk7ARFC/view?usp=sharing

Just ran into this annoying problem.

Anything better from MonkeyBread Software?

Report your finding as an Issue

That’s too much, something probably can be easily enhanced.

Already reported, case #65918

ParseDate returns a boolean which verifies if the conversion happened correctly. However the DateTime.FromString does not seem to have a way to check if a conversion occurred correctly. Am I missing something? I hate to just assume every date conversion will always work.

If something goes wrong with DateTime.FromString you will get a runtime exception. This is mentioned in the documentation, but it neglects to say what kind of exception to catch. You’ll have to test that, I’m no longer at my desk today.

https://documentation.xojo.com/api/data_types/datetime.html#datetime-fromstring

It raises an exception for most cases, but seems that there are some cases it silently ignores some invalid values as

I guess you are using Windows.

This on Mac:

No good info:

Parse error: date needs to be in the format of YYYY-MM-DD HH:MM or YYYY-MM-DD

So add multi-platform “inconsistent behavior” to the issue. :wink:

1 Like

Yeah as far as what you can throw at it, ParseDate is a much more “durable” function.

That’s why it takes a locale