note 81571 added to function.strtotime

From: Date: Tue, 04 Mar 2008 12:43:24 +0000
Subject: note 81571 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-136731@lists.php.net to get a copy of this message
Requirement: From a date of birth, work out an age on a given date. Problem: Solutions I found were not accurate enough, not incorporating leap years.. and often up to a week out for a 30 year old. Solution: While the following still probably has it's flaws, it worked for me to enough precision. <?php //Get the date of birth as timestamp from american format $birthtime = strtotime( $birth_month. "/" . $birth_day . "/" . $birth_year ); //Get the required date as timestamp (or could do time() for today) $reqtime = strtotime( $req_month. "/" . $req_day . "/" . $req_year ); //Simple Calculation to get age $calc_age = floor ( ($reqtime - $birthtime) / 60*60*24*365.25) ) ; ?> Testing: I've tested this for those aged 18 to 90. And it is accurate to the day. Obviously it doesn't take time of birth into account.. but really.. who cares? ---- Server IP: 87.124.64.96 Probable Submitter: 80.229.59.178 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/81571 Del: integrated -- https://master.php.net/note/delete/81571/integrated Del: useless -- https://master.php.net/note/delete/81571/useless Del: bad code -- https://master.php.net/note/delete/81571/bad+code Del: spam -- https://master.php.net/note/delete/81571/spam Del: non-english -- https://master.php.net/note/delete/81571/non-english Del: in docs -- https://master.php.net/note/delete/81571/in+docs Del: other reasons-- https://master.php.net/note/delete/81571 Reject -- https://master.php.net/note/reject/81571 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136731) next »