note 110970 rejected from function.date-diff by googleguy
| From: | googleguy@php.net | Date: | Mon, 31 Dec 2012 20:32:57 +0000 |
| Subject: | note 110970 rejected from function.date-diff by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192717@lists.php.net to get a copy of this message | ||
Note Submitter: a dot ross at keacampers dot de
----
Hi There,
is still confused on the php changes. My script worked fine until the release of php 5.3. I tried
many things but i always got this error:
Warning: date_diff() expects parameter 1 to be DateTime, string given in /
the code:
if (! function_exists(date_diff)) {
function date_diff($start_date, $end_date, $returntype="d")
{
if ($returntype == "s")
$calc = 1;
if ($returntype == "m")
$calc = 60;
if ($returntype == "h")
$calc = (60*60);
if ($returntype == "d")
$calc = (60*60*24);
$_d1 = explode("-", $start_date);
$y1 = $_d1[0];
$m1 = $_d1[1];
$d1 = $_d1[2];
$_d2 = explode("-", $end_date);
$y2 = $_d2[0];
$m2 = $_d2[1];
$d2 = $_d2[2];
if (($y1 < 1970 || $y1 > 2037) || ($y2 < 1970 || $y2 > 2037))
{
return 0;
} else
{
$today_stamp = mktime(0,0,0,$m1,$d1,$y1);
$end_date_stamp = mktime(0,0,0,$m2,$d2,$y2);
$difference = round(($end_date_stamp-$today_stamp)/$calc);
return $difference;
}
I hope someone have a idea?