Page 1 of 1

Isdate function

Posted: Mon May 06, 2024 9:13 am
by loulou2522
Can someone have a solution to verify if an entry is a valid date
Thanks

Re: Isdate function

Posted: Mon May 06, 2024 9:54 am
by Piero

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

Posted: Mon May 06, 2024 10:06 am
by STARGÅTE
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.

Re: Isdate function

Posted: Tue May 07, 2024 11:20 pm
by boddhi
STARGÅTE wrote: You can use ParseDate.
This function gives -1, if the date was invalid.
Note only one exception : With "12/31/1969 23:59:59" that returns, for technical reason, -1 whereas it's valid datetime

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")

Re: Isdate function

Posted: Wed May 08, 2024 1:04 am
by Little John
Little 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.
https://www.purebasic.fr/english/viewto ... 43#p613543