Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to validate dates? (month and day only)
Message
From
29/12/2000 10:31:12
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00457589
Message ID:
00457763
Views:
20
>>>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
Hi Joe,
First case only handles with assumption Feb29 always invalid. I don't have an idea about why it's needed and provided the 'otherwise' portion (where Feb29 might be valid on cases such this day and month is queried for the current year).
You're right on error part. I assumed (:) Joe's spinner and combo already limited the days and months choosable.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform