|
-
Sep 5th, 2004, 08:07 PM
#1
Thread Starter
Lively Member
date function
Dim strDOB as string
strDOB = "03/28/1963"
How to calculate this person age using date function?
Thank you.
vb999
-
Sep 5th, 2004, 08:16 PM
#2
Hyperactive Member
This will give you only the age in year
Code:
INT(DateDiff("d", "03/28/1963", Now) / 365.25)
-
Sep 5th, 2004, 08:17 PM
#3
The picture isn't missing
Use DateDiff:
Msgbox datediff("YYYY",strDOB,now)
Edit: Nevermind my solution sucks.
Last edited by BuggyProgrammer; Sep 5th, 2004 at 08:23 PM.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Sep 5th, 2004, 08:40 PM
#4
Thread Starter
Lively Member
[RESOLVED]
Thank you, dRAMmer.
INT(DateDiff("d", "03/28/1963", Now) / 365.25) -- works!
vb999
-
Sep 5th, 2004, 08:53 PM
#5
Fanatic Member
The interval argument for DateDiff function has these settings:
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
Any idea why DateDiff("yyyy", strDOB, Now) returns one extra year?
I think this will work too:
VB Code:
Int(DateDiff("m", strDOB, Now) / 12)
Cheers!
-
Sep 5th, 2004, 09:15 PM
#6
Hyperactive Member
daydee,
your code good, but if vb999 would encounter a leap year, it would cause a bit of problem, 365.25 is the average year, so i think he's better of using it, cheers!
also, Datediff gives us an extra year because, as long as it encounters a different value in year it will compute for it, anyway it make sense since from Dec.31,2004 to Jan.1,2005, a year has elasped 
so for:
Code:
DateDiff("yyyy", "12/31/2004",01/01/2005")
gives use 1
-
Sep 6th, 2004, 12:59 AM
#7
Fanatic Member
LOL I guess since we're dividing the year of birth by 365.25 (365 days + 5 hours , 48 minutes and 46 seconds.) we should really be using the hour of birth in the equation as well!
Like, suppose you were born February 29, 1972 at 10 PM. Then 365 and one-quarter days went by and behold, technically the first anniversary of your birth hour would come on March 1, 1973, at about 4 AM. 
The second and third anniversaries would fall on March 1, at 10 AM and 4 PM respectively.
Comes year four (1976), and your anniversary is back where it started, February 29 at 10 PM.
It gets worst...
If you were born February 28, 1972, at 4 AM, you were supposed to celebrate all your non-leap-year birthdays on February 27.
I understand now why the " / 365.25" equation is ultimately the right way to determine one's exact age but like I said...
I think for this to be valid, we should add in the exact hour of birth as well. Does that make sense?
Cheers!
-
Sep 6th, 2004, 01:08 AM
#8
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|