envexlabs Posted June 11, 2008 Share Posted June 11, 2008 Hey, How would i figure out what weekly time frame the user is in. ie, it's wednesday, so i want to figure out which date monday was and which day sunday will be. I'm trying to filter out jobs by weekly time frames, and i just can't figure this problem out. Thanks, envex Link to comment https://forums.phpfreaks.com/topic/109760-weekly-time-frame/ Share on other sites More sharing options...
Psycho Posted June 11, 2008 Share Posted June 11, 2008 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 More sharing options...
Psycho Posted June 11, 2008 Share Posted June 11, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.