Home > Archive > Visual Basic Syntax > February 2005 > Getting Age from Date of Birth
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Getting Age from Date of Birth
|
|
| Brad M. 2005-01-28, 4:00 am |
| How would I write a function that would return the age of a person given
their date of birth?? I'm assuming this isn't an uncommon request, and I'm
sure there is a quicker way to write it than how I would.
Any help is greatly appreciated!
Best Regards,
Brad
| |
| Bob Butler 2005-01-28, 4:00 am |
| "Brad M." <anonymous@discussions.microsoft.com> wrote in message
news:%238FBx9NBFHA.2552@TK2MSFTNGP09.phx.gbl
> How would I write a function that would return the age of a person
> given their date of birth?? I'm assuming this isn't an uncommon
> request, and I'm sure there is a quicker way to write it than how I
> would.
Check the DateDiff function
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| Douglas J. Steele 2005-02-05, 4:00 pm |
| "Bob Butler" <tiredofit@nospam.com> wrote in message
news:eQROrCOBFHA.936@TK2MSFTNGP12.phx.gbl...
> "Brad M." <anonymous@discussions.microsoft.com> wrote in message
> news:%238FBx9NBFHA.2552@TK2MSFTNGP09.phx.gbl
>
> Check the DateDiff function
Actually, you need a little more than the DateDiff function, Bob.
DateDiff("yyyy", #12/31/2004#, #1/1/2005#) will return a difference of 1
year, but you'd hardly want to say that a one day old baby was 1.
To ensure that the year isn't incremented until the birthday has occurred,
you need to use:
Age=DateDiff("yyyy", dtmDOB, Date()) - _
Iif(Format$(Date(), "mmdd") < Format(dtmDOB, "mmdd"), 1, 0)
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
| |
| Bob Butler 2005-02-05, 4:00 pm |
| "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in
message news:uy$C8t4CFHA.2288@TK2MSFTNGP14.phx.gbl
> "Bob Butler" <tiredofit@nospam.com> wrote in message
> news:eQROrCOBFHA.936@TK2MSFTNGP12.phx.gbl...
>
> Actually, you need a little more than the DateDiff function, Bob.
I know; I was just pointing the OP in the right direction and hoping there'd
be some experimentation... the old "give a man a fish" theory.
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| Brad M. 2005-02-05, 8:58 pm |
| Hi Guys,
Just so you know, I had in fact discovered I had to do some 'monkeying'
myself, and I got it to work. Thanks for the direction, and thanks for the
example anyway!
Best Regards,
Brad
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:OhdM0i5CFHA.2568@TK2MSFTNGP10.phx.gbl...
> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in
> message news:uy$C8t4CFHA.2288@TK2MSFTNGP14.phx.gbl
>
> I know; I was just pointing the OP in the right direction and hoping
> there'd
> be some experimentation... the old "give a man a fish" theory.
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
|
|
|
|
|