Question about date calculations

From: Date: Thu, 29 Dec 2011 21:22:15 +0000
Subject: Question about date calculations
Groups: php.general 
Request: Send a blank email to php-general+get-316124@lists.php.net to get a copy of this message
Hello List, I am using PHP version 5.2.6. I have a page I am trying to create where I am comparing the values of two MySQL date fields with the current date. One of the MySQL Date fields is a class start date, the other is the class end date. First I need to calculate the number of days between class start and end date. Then based on the number of days between these to dates I have to find out how close the current date is to the class end date. So far in looking at the functions that are available at http://www.php.net/manual/en/ref.datetime.php I have not been able to figure out how to do what I need to do. Below is a snippet showing approximately what I am trying to do. <?PHP ... $dteStartDate[$intCnt]= New DateTime($row[10]); $dteEndDate[$intCnt]= New DateTime($row[11]); ... $dteCheckDate=date('Y-m-d'); $intDayCnt=$dteEndDate[$i]-$dteStartDate[$i]; if (($dteCheckDate>=($dteEndDate[$i]-7) && $dteCheckDate<=($dteEndDate[$i]+1)) && $intDayCnt<16) ... ?> My start date is 12/26/2011, the end date 1/8/2012 so the value for &intDayCnt should be 13, but it is coming up as 0. Also the check date which is 12/29/2011 is being calculated as after my end date. Can someone point me in the direction of what I need to do to have the comparisons I am doing work. Eric Lommatsch.

« previous php.general (#316124) next »