How do I compute someone's age in a query

A

Ann Marie

I was wondering if anyone out there could give me the
syntax of how to compute someone's age in a query? I
tried using the datepart function, extracting the year
and then subtracting that value from the year I extracted
using the datepart function again and the now() function
for the current year. It works, however, it's basing the
age on the values of the year which isn't correct if
someones birthday is let's say in September. Here's what
I have so far:

Age: DatePart('yyyy',Now())-DatePart('yyyy',[birthday])

I must somewhere include a check on the month too. Right?
But how? THANK YOU TO ANY SOUL WHO CAN HELP ME!!!
Ann Marie
 
A

Aaron

You can input it as below:

Age: DateDiff("yyyy", [birthday],now( ) )


Aaron _~@
Yang _`\<,_
? (*)/&(*) China Boy
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
 
J

John Spencer (MVP)

Age: DateDiff("yyyy",Birthday,Date()) +
Cint(Format(Birthday,"mmdd")< Format(Date(),"mmdd"))
 
F

fredg

I was wondering if anyone out there could give me the
syntax of how to compute someone's age in a query? I
tried using the datepart function, extracting the year
and then subtracting that value from the year I extracted
using the datepart function again and the now() function
for the current year. It works, however, it's basing the
age on the values of the year which isn't correct if
someones birthday is let's say in September. Here's what
I have so far:

Age: DatePart('yyyy',Now())-DatePart('yyyy',[birthday])

I must somewhere include a check on the month too. Right?
But how? THANK YOU TO ANY SOUL WHO CAN HELP ME!!!
Ann Marie

Ann Marie,
In a query:
Age: DateDiff("yyyy", [DOB], Date()) - IIF(Format([DOB], "mmdd") >
Format(Date(), "mmdd"), 1, 0)

Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],"mmdd")>Format(Date(),
"mmdd"),1,0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top