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: EDIT, Thanks to 开发者_开发知识库the below answer:
' public function get_weeks () { $valid_dates = array(); $date_counter = 0;
$date_counter = strtotime("next thursday"); // I love being a lazy bastard! $i = 0; while ($i < 10) {
array_push($valid_dates, $date_counter);
$date_counter = strtotime("previous sunday 23:59:59", $date_counter);
$i++;
}
foreach ($valid_dates as $date) {
$values[$date]['start'] = $date;
$values[$date]['end'] = $date + 604800;
}
return $values;
}'
I wrote a solution for a similar question yesterday here. It was the wrong approach for the OP's question but it goes into the right direction for your question. I can't modify it right now due to time constraints, but it shouldn't be too hard to do.
Hint: Strtotime can do things like
$timestamp = strtotime("last monday 0:00");
strtotime("next sunday 23:59:59", $timestamp);
精彩评论