note 59792 added to function.date

From: Date: Thu, 15 Dec 2005 20:32:18 +0000
Subject: note 59792 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-100229@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59792 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59792&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59792&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59792&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59792&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59792&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59792&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59792&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59792&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100229) next »