View Full Version : calculating age.


ckitzman
01-19-2007, 10:30 AM
age: DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd"))

Dob is stored yyyyddmm

I thought this above function looks ok. When I run it, I get a data type mismatch in criteria expression.

What am I missing?
Any help would be appreciated.
Thanks

namliam
01-19-2007, 11:38 AM
DOB has to be a date/time field, you have a string... this is causing the problem

Try using the function DateSerial to transform the string to a date and ... it should work

ckitzman
01-19-2007, 11:50 AM
DOB has to be a date/time field, you have a string... this is causing the problem

Try using the function DateSerial to transform the string to a date and ... it should work

Like this?:
DOB: Mid([date_of_birth],5,2) & "/" & Mid([date_of_birth],7,2) & "/" & Mid([date_of_birth],1,4)

I have this in the same query. I'm not familiar with DateSerial, sorry.

RuralGuy
01-19-2007, 12:29 PM
Have you looked up DateSerial in VBA Help to see how it works?

ckitzman
01-19-2007, 01:31 PM
[QUOTE=RuralGuy]Have you looked up DateSerial in VBA Help to see how it works?[/QUOTE

obviously not. i don't know VB, just a rookie trying to get rid of a pesky error.
Thanks

RuralGuy
01-19-2007, 01:56 PM
Well don't take this wrong but do you plan to be a rookie forever? These forums are usually to help people help themselves. Do you need help getting to VBA Help?

ckitzman
01-19-2007, 02:24 PM
Well don't take this wrong but do you plan to be a rookie forever? These forums are usually to help people help themselves. Do you need help getting to VBA Help?
naw, i got it. thanks. I was trying to do too many things in one query. I separated the steps out and it's working fine now. Thanks