note 38692 deleted from function.date by didou

From: Date: Fri, 02 Jan 2004 23:43:02 +0000
Subject: note 38692 deleted from function.date by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62822@lists.php.net to get a copy of this message
Note Submitter: Kellie -you know what- Lumenlab.com ---- Here is a function to calculate the number of days between a start and end date from a mysql datetime field. $first_date = "2003-12-17 18:41:00"; // your mysql datetime $last_date = "2004-01-02 02:05:39"; //your mysql datetime //----------- // format the dates without hours, minutes, or seconds //---------- $f_day = mktime(0,0,0, date("m",strtotime($first_date)), date("d",strtotime($first_date)), date("Y",strtotime($first_date))); $l_day = mktime(0,0,0, date("m",strtotime($last_date)), date("d",strtotime($last_date)), date("Y",strtotime($last_date))); //---------- // get the difference between the 2 dates, divide by 86400 //---------- $days = ($l_day - $f_day) / 86400; //86400 seconds in a day //-------- // now print the results //--------- echo "<br>"; echo "First day: " . date("m/d/Y",strtotime($first_date)); echo "<br>"; echo "Last day: " . date("m/d/Y",strtotime($last_date)); echo "<br>"; echo "Total days: $days";

« previous php.notes (#62822) next »