Jump to content

weekly time frame


envexlabs

Recommended Posts

Hmm, are you considering Sunday as the last day of the week (Mon - Sun)?

 

Becauser in actuality Sunday is the first day of the week and Monday is the 2nd day of the week. Saturday is the last day. (Sun - Sat)

 

The former will be slightly more complex to do, but definitely doable.

 

 

Link to comment
https://forums.phpfreaks.com/topic/109760-weekly-time-frame/#findComment-563278
Share on other sites

Here is a solution for both:

 

<?php

$today = time();

$dow = date("w", $today);

echo "Week from Sunday to Saturday<br>";
$sunday = $today - ($dow * 86400);
$saturday = $today + ((6-$dow) * 86400);
echo "Today is: ".date('F j, Y', $today)."<br>";
echo "First DOW (Sunday) is: ".date('F j, Y', $sunday)."<br>";
echo "Last DOW (Saturday) is: ".date('F j, Y', $saturday)."<br>";

echo "<br><br>";
echo "Week from Monday to Sunday<br>";
$monday = ($dow==0)?$today - (6 * 86400):$today - (($dow-1) * 86400);
$sunday = ($dow==0)?$today:$today + ((7-$dow) * 86400);
echo "Today is: ".date('F j, Y', $today)."<br>";
echo "First DOW (Monday) is: ".date('F j, Y', $monday)."<br>";
echo "Last DOW (Sunday) is: ".date('F j, Y', $sunday)."<br>";


?>

Link to comment
https://forums.phpfreaks.com/topic/109760-weekly-time-frame/#findComment-563286
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.