Dim strDOB as string
strDOB = "03/28/1963"
How to calculate this person age using date function?
Thank you.
vb999
Printable View
Dim strDOB as string
strDOB = "03/28/1963"
How to calculate this person age using date function?
Thank you.
vb999
This will give you only the age in year
Code:INT(DateDiff("d", "03/28/1963", Now) / 365.25)
Use DateDiff:
Msgbox datediff("YYYY",strDOB,now)
Edit: Nevermind my solution sucks.
Thank you, dRAMmer.
INT(DateDiff("d", "03/28/1963", Now) / 365.25) -- works!
vb999
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:Cheers!VB Code:
Int(DateDiff("m", strDOB, Now) / 12)
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:gives use 1Code:DateDiff("yyyy", "12/31/2004",01/01/2005")
:lol:
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. :eek:
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. :confused:
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! :wave:
:thumb: :D