I have been putting a weekly view calendar together that lets the user move back or forwards a week using buttons on a form. Everything works well except that when the calendar first opens it this that the current day if the beginning of the week so the rest of the days are all out.
Here’s what I have so far…
if(isset($_POST['add_week'])){
$last_week_ts = strtotime($_POST['last_week']);
$display_week_ts = $last_week_ts + (3600 * 24 * 7);
} else if (isset($_POST['back_week'])) {
$last_week_ts = strtotime($_POST['last_week']);
$display_week_ts = $last_week_ts - (3600 * 24 * 7);
} else {
$display_week_ts = floor(time() / (3600 * 24)) * 3600 * 24;
}
$week_start = date('d-m-Y', $display_week_ts);
for ($i = 0; $i < 7; $i++) {
$current_day_ts = $display_week_ts + ($i * 3600 *24);
echo date('d-m-Y', $current_day_ts);
}
I know what the problem is, the line
$display_week_ts = floor(time() / (3600 * 24)) * 3600 * 24;
It calls the current day but $week_start needs to be the first day of the week but I have tried everything I can find. I have tried
$display_week_ts = strtotime("Monday noon");
which seems to work well until the diary reaches Monday 29th October at which point it seems to skip a day and makes 29th October a Tuesday instead.
I found another topic on this site that found the beginning of the week but I have been unable to implement any of them successfully
I will be very grateful for any assistance in this matter, I’ve been working on it for three days now…
Try this:
Now
$mondaycontains the date for Monday of the current week. Store this object in the session. When you need to move to next week, find the next Monday withTo find the previous Monday, use
After finding the new Monday, store it back into the session.