note 39927 added to function.date

From: Date: Mon, 16 Feb 2004 01:50:54 +0000
Subject: note 39927 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-65193@lists.php.net to get a copy of this message
I was fed up with trying to figure out birthdays. The leap year codes always messed things up. Those always seem to calculate age based on number of days between A and B. This is simple math between the two different years. if the birthday is coming up, we subtract 1 year so they don't magically get 1 year older. The code below could of been shortend but was done this way for personal reasons. I use the following to calculate age, it works. i've tested it. PS birthdate I store in epoch format. function age($born) { $topofthehour = mktime(0,0,0,date("m"),date("d"),date("Y")); if(mktime(0,0,0,date("m",$born),date("d",$born), date("Y",$topofthehour)) == $topofthehour){ #Today Is Their Birthdate return ( date("Y",$topofthehour) - date("Y", $born) ); }elseif(mktime(0,0,0,date("m",$born),date("d",$born), date("Y",$topofthehour)) > $topofthehour){ #Birthdate Is In The Future $calc = (date("Y",$topofthehour) - date("Y", $born) - 1); return $calc; }else{ #Birthdate Has Passed $calc = (date("Y",$topofthehour) - date("Y", $born)); return $calc; } } ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39927 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39927&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39927&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65193) next »