Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DateDiff to work out if someones age is valid 1

Status
Not open for further replies.

parkers

Vendor
Oct 21, 2002
157
0
0
GB
Hi ... I'm having some problems with the DateDiff command with the following scenario:

Need to work out if someones age is greater than for example 20 ... I am able to get to the following:

DateDiff("yyyy",[dateOfBirth],Now()) >=20

Unfortunately this only looks to the year calculation ... i.e. if someone enters a Date of Birth of 4th December 1983 then it will accept based on year calculation.

Is there a neat way to incorporate days and months to ensure the >= 20 years old rule is valid?

Any help would be appreciated...

SP
 
SP,

after the year is validated, you can compare the dd/mm of today and the BirthDate.


DateDiff("yyyy",[dateOfBirth],Now()) >=20 then
if format([dateOfBirth],&quot;dd/mm&quot;) <= format(Now(),&quot;dd/mm&quot;) then
'He/she is 20 or older
end if
end if
 
Great help ...

I modified your code to the following which for me works perfectly ...

DateDiff(&quot;yyyy&quot;,[dateOfBirth],Now())>=20
And
Format([dateOfBirth],&quot;dd/mm&quot;)<=Format(Now(),&quot;dd/mm&quot;)

Thanks
SP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top