note 59792 deleted from function.date by derick

From: Date: Sun, 15 Jan 2006 12:35:39 +0000
Subject: note 59792 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-101807@lists.php.net to get a copy of this message
Note Submitter: djwood at gmail dot com ---- I've found these user entries so useful over time, I finally decided to return the favor. Hopefully this helps someone. I searched for this for a while. I was trying to figure out how many days elapsed between two dates, or in other words the difference between two dates. I set it up in PHP with some other users suggestions: $init_date = mktime(12,0,0,$arrival_month,$arrival_day,$arrival_year); $dst_date = mktime(12,0,0,$departure_month,$departure_day,$departure_year); $offset = $dst_date-$init_date; $days_elapsed = floor($offset/86400); It worked ok, except I noticed it had some trouble if you were spanning months, (i.e. 03-29-2005 to 04-10-2005) it would sometimes count one less than the actual elapsed days. So obviously this is not good. IF YOU HAVE ACCESS TO A MYSQL DATABASE: I found this to be the easiest and most accurate way: ---------------------------------------------------------- $elapsed_query = mysql_query("SELECT to_days( '$depart' ) - to_days( '$arrive' ) AS days_elapsed")or die("Query failed"); $days_elapsed = mysql_result($elapsed_query, 0, 0); --------------------------------------------------------- It's working great for me, I hope this helps someone.

« previous php.notes (#101807) next »