faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 16 people (69%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I loop over a range of dates?

Jun 10th, 1999 07:00
Nathan Wallace, Zoran Regvart


$from_month = 12;
$from_day = 30;
$from_year = 1999;
$till_month = 3;
$till_day = 2;
$till_year = 2000;

$from_date = mktime(0, 0, 0, $from_month, $from_day, $from_year);
$till_date = mktime(0, 0, 0, $till_month, $till_day, $till_year);

for($i = $from_date; $i <= $till_date; $i+=86400) {
    echo date("l, F d Y.",$i)."<br>"
}