note 38692 added to function.date

From: Date: Fri, 02 Jan 2004 23:22:12 +0000
Subject: note 38692 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-62821@lists.php.net to get a copy of this message
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"; ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38692 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38692&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38692&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62821) next »