Re: Date Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux