TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Age through date (http://www.talkphp.com/absolute-beginners/1424-age-through-date.html)

Haris 11-10-2007 01:55 AM

Age through date
 
I want to calculate the age of the date in years, months and days.

An example could be:

15-sep-1997
You're 10 years 2 months and 25 days old.

5-Nov-2007
You're 5 days old.

10-Oct-2007
You're 1 month old.

Nor 11-10-2007 02:54 AM

Do you want to calculate it based on the date provided and the current date (as in now), and subtract the two? Then output them separately( Years: Months: Days: )

Salathe 11-10-2007 03:17 AM

A good starting point might be Wildhoney's Calculating an Age from Date of Birth topic. :)

Haris 11-10-2007 11:12 AM

Quote:

Originally Posted by Nor (Post 3883)
Do you want to calculate it based on the date provided and the current date (as in now), and subtract the two? Then output them separately( Years: Months: Days: )

Yes, that's true. :)

CMellor 11-10-2007 04:51 PM

Hey, this may not be what you EXACTLY need, but maybe you can expand on it:

PHP Code:

//--------------------
// Generate age based on user's birthday
//--------------------
function getage($_dob) {
    
$dob date("Y-m-d"strtotime($_dob));
    
$ageparts explode("-"$dob);
        
    
$age date("Y-m-d") - $dob;
        
    return (
date("nd") < $ageparts[1] . str_pad($ageparts[2], 2'0'STR_PAD_LEFT)) ? $age -= $age;




All times are GMT. The time now is 10:43 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0