note 58151 added to function.mktime

From: Date: Tue, 25 Oct 2005 19:30:16 +0000
Subject: note 58151 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-97594@lists.php.net to get a copy of this message
There was a birthdate calculator posted above which from reading the code seems flawed in my logic. Oddly, most code I see to calculate birthdates tries to use the difference between the years to find it's result, which can be flawed (if my birthday is Jan 10th and I'm 19, and its Jan 5th, these scripts might still think I am 20). Basically this creates a timestamp with the desired birthdate and only checks if the given birthdate has passed this year yet or not. Simple & reliable age in years! Here's the code I use to do this, which, yes, could be better written: $bd = mktime(0,0,0,$month,$day,$year); if (date("n") > intval($month)) {$before = FALSE;} if (intval(date("j")) >= intval($day)) {$before = FALSE;} else {$before=TRUE;} if ($before == TRUE) { $age = (date("Y")-$year)-1; } else { $age = (date("Y")-$year); } ---- Manual Page -- http://www.php.net/manual/en/function.mktime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58151 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58151&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58151&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58151&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58151&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58151&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58151&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58151&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58151&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97594) next »