note 97186 deleted from function.date-diff by danbrown

From: Date: Wed, 07 Apr 2010 14:19:21 +0000
Subject: note 97186 deleted from function.date-diff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167761@lists.php.net to get a copy of this message
Note Submitter: carrandry at gmail dot com ---- 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.

« previous php.notes (#167761) next »