Tech Tip: Checking for valid dates based on regional settings
PRODUCT: 4D | VERSION: 12.1 | PLATFORM: Mac & Win
Published On: May 12, 2011
Date are formatted in 4D depending on the regional format selected within the OS. For example;
- if English (US) is selected the date is formatted as mm/dd/yyyy
- if English (UK) is selected the date is formatted as dd/mm/yyyy
If you allow your user to enter a date you may want to verify it is valid for the selected region. Here is a short example of how to test if the date is valid for the selected regional format:
C_DATE(myDate) myDate:=!28/09/2010! ` user entered value here If (myDate=Date(String(myDate))) ` myDate is valid for the selected region else ` myDate is invalid for the selected region end if |
In this way, we compare the system date short string (converted back to a date) of myDate against the actual contents of myDate to confirm they match and only execute the code if they do match; if they do not matchy the date is invalid for the selected regional format.
This would be useful if you are unsure if the date entered is valid for the currently selected regional setting.