note 78077 deleted from function.mktime by bjori
| From: | bjori@php.net | Date: | Thu, 27 Sep 2007 12:29:08 +0000 |
| Subject: | note 78077 deleted from function.mktime by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-130843@lists.php.net to get a copy of this message | ||
Note Submitter: Carlos Pauluk carloseduardopauluk@gmail
Reason: useless
----
I've been using the mktime() function to calculate difference between dates. It works fine to
me until I need to do calculation in more wide dates, like 01/01/2070.
There will be a huge problem to all those that use timestamps to calculate dates after
2038-01-19T03:14:08+0000Z (like posted by PHPCoder).
I got a code from "google" (thanx to Amrit Hallan) that can successfully calculate the
difference *in days* between two dates.
<?php
function dateDiff($dformat, $endDate, $beginDate) {
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
return $end_date - $start_date;
}
?>
You can use it like these:
<?php
echo dateDiff("/", "01/31/2070", "01/31/2000");
?>
It should returns 25568 (days between).
I wish that help.