Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to validate dates? (month and day only)
Message
 
 
To
29/12/2000 09:48:59
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00457589
Message ID:
00457757
Views:
26
>>A user enters a day in a spinner. They then choose a month from a combobox. They do not enter a year. Is there an
>>easy way to tell if the month/day combination is valid?
>
>Joe,
>If it's kind of 'On every 23rd of June' thing then you could check :
>isValid=!empty(date(1999,lnMonth,lnDay))
>
>Otherwise :
>isValid=!empty(date(2000,lnMonth,lnDay)) ;
> and iif(lnDay=29 and lnMonth=2,HandleFeb29(),.t.)

Cetin,

Was wondering what the "Otherwise" is for...your first check handles everything, including Feb 29, 2000... I am sure I am missing something, but I think your first method is very slick and handles everything?

One thing to remember about DATE()...it will return empty when an invalid date is built, like DATE(1999,2,29) (returns empty date), but it will error out if a totally invalid month or day is entered:

DATE(1999,13,30) (errors out because month cannot be greater than 12)
DATE(2000,11,40) (errors out because daycannot be greater than 31)

Kinda quirky, but your spinners probably already have ranges on them to make sure you don't get into this situation...

Good luck!

JoeK
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform