The above code works as expected, however if DateAsString becomes 'End Date', the function receives a string that looks like 'DATE#End Date', and will cause an exception.
Is there any way to pre-validate the string before converting it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Other option is to manually check if passed string is matching required format:
1. Prepare function to check if single character in string is a character number (return true/false)
2. Prepare function to check if character is dash (return true/false)
3. Run this functions for all characters, one by one
4. If at least one call return false, do not perform conversion
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
using the STRING_TO_DATE function, I have found that an improperly formatted string could cause an Access Violation exception in the program.
The above code works as expected, however if DateAsString becomes 'End Date', the function receives a string that looks like 'DATE#End Date', and will cause an exception.
Is there any way to pre-validate the string before converting it?
Hi. You can use FSTRING_TO_DT from OSCAT library (with additional TO_DATE conversion).
https://store.codesys.com/oscat-basic.html
In case of invalid input string (like 'End Date') you just got 'NULL' date (1970-1-1) without any exception.
Other option is to manually check if passed string is matching required format:
1. Prepare function to check if single character in string is a character number (return true/false)
2. Prepare function to check if character is dash (return true/false)
3. Run this functions for all characters, one by one
4. If at least one call return false, do not perform conversion