DateDiff

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!
I am trying to write a query to display the actual age of a person. The only thing that I could find that would give me something close is:

DateDiff("yyyy",[dob],Now())

The problem is that the returned answer is the same for the entire year (ie if [dob]=6/1/65 and today is 4/28/04, the age returned is 39 even though we haven't reached the birthday date yet.

Any ideas would be greatly appreciated. Thank you in advance.
 
That's right: DateDiff is very literal. You need to adjust your code so that
it subtracts 1 from the result if the birthday hasn't occurred yet:

DateDiff("yyyy", [dob], Date()) - IIf(Format([dob], "mmdd") < Format(Date(),
"mmdd"), 1, 0)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



John said:
Hi!
I am trying to write a query to display the actual age of a person. The
only thing that I could find that would give me something close is:
DateDiff("yyyy",[dob],Now())

The problem is that the returned answer is the same for the entire year
(ie if [dob]=6/1/65 and today is 4/28/04, the age returned is 39 even though
we haven't reached the birthday date yet.
 
Thank you very much!!
:o)
-----Original Message-----
That's right: DateDiff is very literal. You need to adjust your code so that
it subtracts 1 from the result if the birthday hasn't occurred yet:

DateDiff("yyyy", [dob], Date()) - IIf(Format
([dob], "mmdd") < Format(Date(),
"mmdd"), 1, 0)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



John said:
Hi!
I am trying to write a query to display the actual age
of a person. The
only thing that I could find that would give me something close is:
DateDiff("yyyy",[dob],Now())

The problem is that the returned answer is the same for
the entire year
(ie if [dob]=6/1/65 and today is 4/28/04, the age returned is 39 even though
we haven't reached the birthday date yet.
Any ideas would be greatly appreciated. Thank you in
advance.


.
 
unless i input it incorrectly the only way i could get the correct result was to make the last expression < (less than) and not > (greater than) as you wrote.
--
bob


John said:
Thank you very much!!
:o)
-----Original Message-----
That's right: DateDiff is very literal. You need to adjust your code so that
it subtracts 1 from the result if the birthday hasn't occurred yet:

DateDiff("yyyy", [dob], Date()) - IIf(Format
([dob], "mmdd") < Format(Date(),
"mmdd"), 1, 0)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



John said:
Hi!
I am trying to write a query to display the actual age
of a person. The
only thing that I could find that would give me something close is:
DateDiff("yyyy",[dob],Now())

The problem is that the returned answer is the same for
the entire year
(ie if [dob]=6/1/65 and today is 4/28/04, the age returned is 39 even though
we haven't reached the birthday date yet.
Any ideas would be greatly appreciated. Thank you in
advance.


.
 
You're right: I mistyped. That's the trouble with going from memory! Thanks
for pointing it out.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Bob said:
unless i input it incorrectly the only way i could get the correct result
was to make the last expression said:
--
bob


John said:
Thank you very much!!
:o)
-----Original Message-----
That's right: DateDiff is very literal. You need to adjust your code so that
it subtracts 1 from the result if the birthday hasn't occurred yet:

DateDiff("yyyy", [dob], Date()) - IIf(Format
([dob], "mmdd") < Format(Date(),
"mmdd"), 1, 0)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Hi!
I am trying to write a query to display the actual age of a person. The
only thing that I could find that would give me something close is:

DateDiff("yyyy",[dob],Now())

The problem is that the returned answer is the same for the entire year
(ie if [dob]=6/1/65 and today is 4/28/04, the age returned is 39 even though
we haven't reached the birthday date yet.

Any ideas would be greatly appreciated. Thank you in advance.


.
 
Back
Top