Isdate function

Just starting out? Need help? Post your questions and find answers here.
loulou2522
Enthusiast
Enthusiast
Posts: 553
Joined: Tue Oct 14, 2014 12:09 pm

Isdate function

Post by loulou2522 »

Can someone have a solution to verify if an entry is a valid date
Thanks
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Isdate function

Post 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}$"
User avatar
STARGÅTE
Addict
Addict
Posts: 2260
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Isdate function

Post 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.
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 moreTypeface - Sprite-based font include/module
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Isdate function

Post 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")
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...
Little John
Addict
Addict
Posts: 4804
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Isdate function

Post 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
Post Reply