Hi guys, i have been trawling around looking for a decent and simple way of working out an age from a birthday.

The way i'm working is a date of birth is added to a database then when pulled we echo the actual age and not the d.o.b.

It's probably quite simple but i can't seem to figure it out, Also there may not be an actual day eg 06/2009 instead of 13/06/2009 if you see my meaning.

Any direction would be great!

Thanks again...

How about converting the date string into a UNIX timestamp, then subtracting that stamp from today's stamp?
Something like:

$b_day = strtotime("1/1/1970"); // UNIX time for birthday
$today = strtotime(date("m/d/Y"));
$age = date("your formatting string here", $today - $b_day));
Member Avatar for diafol

Should be clear from the next row but if not:

b_day = strtotime("1/1/1970") //is also in m/d/Y (US) format

@EF - sorry for jumping in.

Thanks guys for the help, sorted now!!

Cheers...

You're welcome emhmk1.
No problem ardav =) I was in a rush so I was worrying more bout typing the code than placing comments. Thanks for filling it in.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.