A
amknorr
I geneaology work we have to work with dates prior to 1900. How can I find
the age of a person born in 1893 who expired in 1960?
the age of a person born in 1893 who expired in 1960?
I was just reading about this and made a sample for to see if it worked for
dates before 1900 and it does. Use DateDiff. Here is the code you would use
in a text box control source of your form or report.
=DateDiff("yyyy", [DOB], [DOE])
the "yyyy" will calculate the time is years. "d" Days and so on. DOB would
be the name of your field for Date of Birth and I used DOE for the name of
your field for Date of Expiration.
John W. Vinson said:I was just reading about this and made a sample for to see if it worked
for
dates before 1900 and it does. Use DateDiff. Here is the code you would
use
in a text box control source of your form or report.
=DateDiff("yyyy", [DOB], [DOE])
the "yyyy" will calculate the time is years. "d" Days and so on. DOB
would
be the name of your field for Date of Birth and I used DOE for the name of
your field for Date of Expiration.
That will be close... but not absolutely accurate, at least by the
traditional
use of "age". DateDiff actually counts year (or day, or second, or...)
boundaries, not full years; so if [DOB] were 12/31/1875 and [DOE] were
1/1/1876 - just a day later - the age would be reported as one year. Or if
[DOB] were 1/1/1931 and [DOE] 12/29/1931 - almost a year - you'ld still
get 0.
You can correct for this with an expression:
DateDiff("yyyy", [DOB], [DOE]) - IIF(Format([DOE], "mmdd") > Format([DOB],
"mmdd"), 1, 0)
John W. Vinson [MVP]
Or simplified to
DateDiff("yyyy", [DOB], [DOE]) + (Format([DOE], "mmdd") > Format([DOB],
"mmdd"))
I love Boolean expressions <g>
John W. Vinson said:Or simplified to
DateDiff("yyyy", [DOB], [DOE]) + (Format([DOE], "mmdd") > Format([DOB],
"mmdd"))
I love Boolean expressions <g>
That's what I used to use... until someone pointed out that in SQL/Server
True
is +1 rather than -1. The IIF is at least platform independent!
John W. Vinson [MVP]
John W. Vinson said:Or simplified to
DateDiff("yyyy", [DOB], [DOE]) + (Format([DOE], "mmdd") > Format([DOB],
"mmdd"))
I love Boolean expressions <g>
That's what I used to use... until someone pointed out that in SQL/Server
True
is +1 rather than -1. The IIF is at least platform independent!
John W. Vinson [MVP]
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.