note 27500 added to ref.datetime

From: Date: Sun, 08 Dec 2002 23:16:40 +0000
Subject: note 27500 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-40548@lists.php.net to get a copy of this message
Here is a quick example of how to iterate through all days between 2 dates (with a adjustable increment) --------------------------------------------------------- //make time stamps from our start & end dates $start_time = mktime(0,0,0,$start_month,$start_day,$start_year); $end_time = mktime(0,0,0,$end_month,$end_day,$end_year); //find the number of days between start_time & end_time $days = ($end_time - $start_time) / (24 * 3600); //we want to count the days including the first .. $days++; //select a 1 week interval .. $inc=7; //find all days (actually periods since we use a increment) for ($i=0;$i<$days;$i+=$inc) { //calculate start & end of period using some magic of mktime :) $start_date = date("Y-m-d", mktime(0,0,0,$start_month,$start_day+$i,$start_year)); $end_date = date("Y-m-d", mktime(0,0,0,$start_month,$start_day+$i+$inc-1,$start_year)); //print it all ... print("Period start:" . $start_date . "\n"); print("Period end: " . $end_date . "\n"); } -- http://www.php.net/manual/en/ref.datetime.php http://master.php.net/manage/user-notes.php?action=edit+27500 http://master.php.net/manage/user-notes.php?action=delete+27500 http://master.php.net/manage/user-notes.php?action=reject+27500

« previous php.notes (#40548) next »