Age test

  • Thread starter Thread starter Paul Mendlesohn
  • Start date Start date
P

Paul Mendlesohn

I would like to know how to test if a person is less than 18 years old.
Something like this:

where dtDateOfBirth is their birthday and Date is the current date

if Date - dtDateOfBirth < 18 then strStatus = "Child"

As you can see I haven't got a clue how to write it.
Thanks
Paul
 
Me.Status = Private Sub Command2_Click()
MsgBox IIf(DateDiff("yyyy", [dtDateOfBirth], Date) - IIf(Format$(Date, "mmdd")
< Format$([dtDateOfBirth], "mmdd"), 1, 0) < 18, "Child", "Adult")
End Sub
 
Hate having no formatting on this site! This:

MsgBox IIf(DateDiff("yyyy", [dtDateOfBirth], Date) - IIf(Format$(Date, "mmdd")

< Format$([dtDateOfBirth], "mmdd"), 1, 0) < 18, "Child", "Adult")

needs to be all on one line in your code.
 
I would like to know how to test if a person is less than 18 years old.
Something like this:

where dtDateOfBirth is their birthday and Date is the current date

if Date - dtDateOfBirth < 18 then strStatus = "Child"

A bit simpler than some of the other suggestions:

If dtDateOfBirth < DateAdd("yyyy", -18, Date()) Then
strStatus = "Adult"
Else
strStatus = "Child"
End If
 
As always the master of terse code, John! But your code would call someone a
"Child" if they were born exactly 18 years ago today! So go wild and add the
equal sign:

If dtDateOfBirth <= DateAdd("yyyy", -18, Date) Then
strStatus = "Adult"
MsgBox strStatus
Else
strStatus = "Child"
MsgBox strStatus
End If

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
Back
Top