Can someone have a solution to verify if an entry is a valid date
Thanks
Isdate function
Re: Isdate function
Code: Select all
~"^(?:(1[0-2]|0?[1-9])\\/(3[01]|[12][0-9]|0?[1-9])|(3[01]|[12][0-9]|0?[1-9])\\/(1[0-2]|0?[1-9]))\\/(?:[0-9]{2})?[0-9]{2}$"Re: Isdate function
You can use ParseDate().
This function gives -1, if the date was invalid.
This function works also with the leap year day Feb 29, which is only valid for specific years.
This function gives -1, if the date was invalid.
This function works also with the leap year day Feb 29, which is only valid for specific years.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Isdate function
Note only one exception : With "12/31/1969 23:59:59" that returns, for technical reason, -1 whereas it's valid datetimeSTARGÅTE wrote: You can use ParseDate.
This function gives -1, if the date was invalid.
Code: Select all
;Test For system With "mm/dd/yyyy" date format
Debug ParseDate("%mm/%dd/%yyyy %hh:%ii:%ss","12/31/1969 23:59:58")
Debug ParseDate("%mm/%dd/%yyyy %hh:%ii:%ss","12/31/1969 23:59:59")
Debug ParseDate("%mm/%dd/%yyyy %hh:%ii:%ss","01/01/1970 00:00:00")
; Test for system with "dd/mm/yyyy" date format
;Debug ParseDate("%dd/%mm/%yyyy %hh:%ii:%ss","31/12/1969 23:59:58")
;Debug ParseDate("%dd/%mm/%yyyy %hh:%ii:%ss","31/12/1969 23:59:59")
;Debug ParseDate("%dd/%mm/%yyyy %hh:%ii:%ss","01/01/1970 00:00:00")If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Except on this sentence...
-
Little John
- Addict

- Posts: 4805
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Isdate function
https://www.purebasic.fr/english/viewto ... 43#p613543Little John wrote:How about introducing a new function named say LastError() into PureBasic?
When that function does not indicate an error, then -1 is a valid date value.
