Jump to content

weekly time frame


envexlabs

Recommended Posts

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
Share on other sites

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.