Array of previous weeks
Posted
by azz0r
on Stack Overflow
See other posts from Stack Overflow
or by azz0r
Published on 2010-06-11T13:44:43Z
Indexed on
2010/06/11
13:53 UTC
Read the original article
Hit count: 376
Hello,
I am trying to create an array of weeks for users to select to view stats week on week.
What I'm looking for is an array that has the timestamp of week start (monday 00.00 to sunday 11.59) that I can then use in MYSQL queries.
Has anyone got an code that might assist? I was thinking of doing something like:
$number_of_weeks = 4;
$week_array = array();
foreach ($number_of_weeks as $week) {
$number_of_weeks--;
$value = $number_of_weeks * 604800;
$StartOfLastWeek = 6 + date("w",mktime());
$week_array[$number_of_week]['start'] =
date('Y-m-d', strtotime("-$StartOfLastWeek day"), $value);
$week_array[$number_of_week]['end'] =
date('Y-m-d', strtotime("-$StartOfLastWeek day"), $value+ 604800);
}
© Stack Overflow or respective owner