Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Minimum Age to Buy
Message
From
08/03/2007 16:28:03
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01202103
Message ID:
01202110
Views:
11
>Hi Gang!
>
>Question....
>
>I am coding up a Pharmacy checkout app.... to handle drugs.
>
>The code has to be able to determine if a person is too young to purchase the drug.
>
>The minimum age will be called sigcap_config.MINAGE
>
>Given Today.... DATE() and their birthdate pse_trans.birthdate how would you code it?
>
>I tried this.....
>
>IF NOT (YEAR(DATE()) - YEAR(Thisform.p_pse_birthdate) >= sigcap_config.minage)
>	MESSAGEBOX('Purchaser needs to be at least ' + ALLTRIM(STR(sigcap_config.minage)) + ' years old to purchase.',0+16+0,"ID Not Accepted",10000)
>	Thisform.p_pseIDapproved = .F.
>	RETURN
>ENDIF
>
>
>But I don't feel comfortable about using the YEAR function this way... something about fractional parts of the year not being involved.
>
>Any better ways?
>
>Thanks!

Given that MinAge is in whole years how about something like
IF GOMONTH(DATE(),MinAge*-12) >= Thisform.p_pse_birthdate)
    && OK
ELSE
    && Error code
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform