note 27500 deleted from ref.datetime by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 17:38:57 +0000 |
| Subject: | note 27500 deleted from ref.datetime by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133177@lists.php.net to get a copy of this message | ||
Note Submitter: eric at nitrateNO_SPAM dot nl
----
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");
}