I am trying to get a period of time with a date such as today is "2011-11-24"
and I want to get 7 days before today:
The values would be :
"2011-11-23", "2011-11-22", "2011-11-21", "2011-11-20",
"2011-11-19", "2011-11-18", "2011-11-17"
I am trying to get a period of time with a date such as today is "2011-11-24"
and I want to get 7 days before today:
The values would be :
"2011-11-23", "2011-11-22", "2011-11-21", "2011-11-20",
"2011-11-19", "2011-11-18", "2011-11-17"
Using the new date/time classes you can do the following:
$p = new DatePeriod(
new DateTime('now'),
DateInterval::createFromDateString('-1 day'),
7,
DatePeriod::EXCLUDE_START_DATE
);
foreach ($p as $t) {
echo $t->format('Y-m-d') . '<br />';
}
See DatePeriod
, DateTime
and DateInterval
.