note 97185 added to function.date-diff
| From: | carrandry at gmail dot com | Date: | Wed, 07 Apr 2010 14:13:26 +0000 |
| Subject: | note 97185 added to function.date-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167758@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. I think this
function needs a fixed days values for the last 2 if conditions to be ok; but how to do it? */
$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/97185
Del: integrated -- https://master.php.net/note/delete/97185/integrated
Del: useless -- https://master.php.net/note/delete/97185/useless
Del: bad code -- https://master.php.net/note/delete/97185/bad+code
Del: spam -- https://master.php.net/note/delete/97185/spam
Del: non-english -- https://master.php.net/note/delete/97185/non-english
Del: in docs -- https://master.php.net/note/delete/97185/in+docs
Del: other reasons-- https://master.php.net/note/delete/97185
Reject -- https://master.php.net/note/reject/97185
Search -- https://master.php.net/manage/user-notes.php