PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Dec 08, 2019 7:48 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 44 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Mon Jun 19, 2006 12:24 pm 
Offline
Site Administrator
User avatar

Joined: Sun May 19, 2002 10:24 pm
Posts: 6887
Send date of birth in format YYYY-MM-DD

Syntax: [ Download ] [ Hide ]
function get_age($year, $month, $day) {
  if (date('m') - (int)$month >= 0) {
      if (date("d") - (int)$day >= 0 || date('m') > $month) {
          return date('Y') - (int)($year);
      }
  }
  return date('Y') - (int)($year) - 1;
}

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 2:20 pm 
Offline
Site Admin
User avatar

Joined: Tue Dec 23, 2003 3:10 am
Posts: 11470
Location: Toronto
you love stroring your dates in different formats don't you ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 2:48 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine
My thoughts exactly =).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 7:28 pm 
Offline
DevNet Master

Joined: Tue Jan 20, 2004 12:11 am
Posts: 4897
Location: Leuven, Belgium
With MySQL the query would be like:

Syntax: [ Download ] [ Hide ]

SELECT YEAR(CURRENT_DATE()) - YEAR(birthday) - (RIGHT(CURRENT_DATE(),5)<RIGHT(birthday,5)) AS age

FROM foo;

 


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 8:40 pm 
Offline
Forum Regular
User avatar

Joined: Mon Nov 14, 2005 5:21 pm
Posts: 878
Similar way.. :)

Syntax: [ Download ] [ Hide ]
function GetAge($DOB) {

        $birth = explode("-", $DOB);



        $age = date("Y") - $birth[0];



        if(($birth[1] > date("m")) || ($birth[1] == date("m") && date("d") < $birth[2]))

        {

                $age -= 1;

        }

        return $age;

}


Man, I had to edit this this 3-4 times before I got it as small as I wanted. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 5:59 am 
Offline
DevNet Master
User avatar

Joined: Tue Nov 02, 2004 6:43 am
Posts: 2704
Location: Ireland
The mighty timestamp would beat you all...:).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 1:21 pm 
Offline
Site Administrator
User avatar

Joined: Sun May 19, 2002 10:24 pm
Posts: 6887

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 2:03 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 6:04 pm 
Offline
Tranquility In Moderation
User avatar

Joined: Sun Feb 06, 2005 8:18 pm
Posts: 5001
Location: Indiana

_________________
- A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 6:38 pm 
Offline
Forum Contributor

Joined: Sun Dec 26, 2004 10:04 pm
Posts: 110


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 1:02 am 
Offline
Forum Contributor
User avatar

Joined: Sun May 07, 2006 5:19 am
Posts: 101


Last edited by Verminox on Wed Jun 21, 2006 1:14 am, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 1:07 am 
Offline
Forum Contributor

Joined: Sun Dec 26, 2004 10:04 pm
Posts: 110


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 1:11 am 
Offline
Forum Contributor
User avatar

Joined: Sun May 07, 2006 5:19 am
Posts: 101


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 2:03 am 
Offline
Forum Regular
User avatar

Joined: Mon Nov 14, 2005 5:21 pm
Posts: 878
Well, the one I posted works just fine. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 2:59 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 44 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group