note 97186 added to function.date-diff

From: Date: Wed, 07 Apr 2010 14:14:10 +0000
Subject: note 97186 added to function.date-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-167759@lists.php.net to get a copy of this message
I am adding the handler for years and months to the previous function posted by eugene - thank you for this, you saved me! function date_diff($start, $end = "NOW") { // ...the old function here... // from 2628288 seconds (1 month) to 31539455 seconds (12 months) elseif($time>=2628288 && $time<=31539455) { // here the following code for $time>=31539456, without the handler for the year... } // over 31539456 seconds (1 year) elseif($time>=31539456) { // Years + Months + Days + Hours + Minutes $pyear = ($edate - $sdate) / 31539456; $preyear = explode('.',$pyear); $pmonth = $pyear-$preyear[0]; $premonth = explode('.',$pmonth*12); /* I can only return years and months, because days will include months and years. */ $timeshift = $preyear[0].' years '. $premonth[0].' months '; } return $timeshift; } Hope it helps. ---- Server IP: 69.147.83.197 Probable Submitter: 79.42.91.68 ---- Manual Page -- http://www.php.net/manual/en/function.date-diff.php Edit -- https://master.php.net/note/edit/97186 Del: integrated -- https://master.php.net/note/delete/97186/integrated Del: useless -- https://master.php.net/note/delete/97186/useless Del: bad code -- https://master.php.net/note/delete/97186/bad+code Del: spam -- https://master.php.net/note/delete/97186/spam Del: non-english -- https://master.php.net/note/delete/97186/non-english Del: in docs -- https://master.php.net/note/delete/97186/in+docs Del: other reasons-- https://master.php.net/note/delete/97186 Reject -- https://master.php.net/note/reject/97186 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167759) next »