Re: Date Question
| From: | Fredrik de Vibe | Date: | Thu, 20 Feb 2003 00:07:52 +0000 |
| Subject: | Re: Date Question | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-25777@lists.php.net to get a copy of this message | ||
cjp@planetoxygene.com (Chris Payne) writes:
> I have the following 2 dates (FOr example):
> 19-02-2003
> 21-02-2003
> How can I easily find out how many nights there are between the 2
> dates? For example, the above would be 2 nights as the 21st would be
> the checkout date.
I guess this will work:
$start = "19-02-2003";
$end = "21-02-2003";
// Split the strings into day, month, year
list($sd, $sm, $sy) = split("-", $start);
list($ed, $em, $ey) = split("-", $end);
// Create unix time stamps for the start and end date
$start_sec = mktime(0, 0, 0, $sm, $sd, $sy);
$end_sec = mktime(0, 0, 0, $em, $ed, $ey);
// Calculate number of days
$num_days = ($end_sec - $start_sec) / 86400; // 86400 secs / day
--
--Fredrik
Faith, n:
That quality which enables us to believe what we know to be
untrue.