• 0

Split array into weeks (this week / next week) by date?


Question

I am trying to build a list of events that is split into weeks.. more specifically: this week, next week and then anything after.

 

Most of the help I can find online is relative to the current day so it's not accurate.

 

I want the 1st heading 'This week' to list all events happening this week (mon - sun) regardless of what day of the week it is... in this weeks case the week starts on 01/06/15 and ends on 07/06/15 < this is true for any date between 01-07 ..

 

The 2nd heading would be 'Next week' and would list all events happening next week 08/06/15 - 14/06/15

 

Since tomorrow is 08/06/15 all events listed here would be be moved to 'This week'.

 

In short, I need to be able to get week start (mon) and end (sun) of the current week, and the following week.

3 answers to this question

Recommended Posts

  • 0

php:

$dayofweek = date("N"); //Return a value between 1 to 7 (Monday to Sunday)

$weekStartEpoch = strtotime("-".($dayofweek-1)." days");
$weekEndEpoch = strtotime("+".(7-$dayofweek)." days");

//You can convert above epoch times to any date format you want
echo date('r', $weekStartEpoch);
echo "</br>";
echo date('r', $weekEndEpoch);  

Haven't tested above but it should work.

 

Edit: tested and fixed some small bugs.

Edit2: fixed weekstart fail.

  • 0
  On 07/06/2015 at 18:47, Seahorsepip said:

php:

$dayofweek = date("N"); //Return a value between 1 to 7 (Monday to Sunday)

$weekStartEpoch = strtotime("-".($dayofweek-1)." days");
$weekEndEpoch = strtotime("+".(7-$dayofweek)." days");

//You can convert above epoch times to any date format you want
echo date('r', $weekStartEpoch);
echo "</br>";
echo date('r', $weekEndEpoch);  

Haven't tested above but it should work.

 

Edit: tested and fixed some small bugs.

Edit2: fixed weekstart fail.

 

 

Works perfect :) thanks

This topic is now closed to further replies.
  • Posts

    • That would be nice, if excel could refresh pivot tables without bugs. Frequently you refresh a pivot and all parameters get lost. Now this will happen automatically. Bravo MS!
    • If one could ever put all the crap of the world in one box, that would be Microsoft.
    • The most corrupt and vile CEO any company ever had ! The only company that makes an insane amount of money decade after decade but doesn't deliver on even barely passable quality to customers, screws over partners and treats employees like trash
    • PSA: Some other versions of Windows are losing support on October 14 too by Usama Jawad All of us here at Neowin likely know pretty well by now that Windows 10 is reaching end of support on October 14, 2025. You can extend support through paid and "free" means, but if you don't, you won't get any more security or feature updates following the aforementioned date. We also highlighted that the Long-Term Servicing Channel (LTSC) version Windows 10 22H2 is also reaching end of support on that date. Now, Microsoft has reminded customers that yet another variant of Windows is reaching end of life on October 14, 2025 too. On the Windows Release Health dashboard, Microsoft has published a reminder that the Enterprise, Education, and IoT SKUs of Windows 11, version 22H2 will hit end of support on October 14 as well. It is important to keep in mind that the Home and Pro variants of Windows 11, version 22H2 already reached end of life on October 8, 2024, and the extra year of lease on life will end for other SKUs within a few months too. Windows 11, version 22H2 for IoT, Enterprise, and Education was released on September 20, 2022, which means that they would have received just over three years of support by the time they "die", compared to the regular two years for Home and Pro. Customers on any of these versions should consider upgrading to version 23H2 or 24H2 as soon as possible, which have end of support dates of November 10, 2026 and October 12, 2027, respectively. Staying on a supported version of Windows is crucial as that allows you to receive regular security updates on your machine. If you're an IT admin, you should immediately begin planning a migration to a supported version of the operating system, and if you're an employee or someone using these versions of Windows in some other scenario, go to Settings > System > About and check out Windows Specifications > Version.
  • Recent Achievements

    • Week One Done
      hhgygy earned a badge
      Week One Done
    • One Month Later
      hhgygy earned a badge
      One Month Later
    • One Year In
      NIKI77 earned a badge
      One Year In
    • Week One Done
      artistro08 earned a badge
      Week One Done
    • Dedicated
      Balaji Kumar earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      637
    2. 2
      ATLien_0
      239
    3. 3
      Xenon
      167
    4. 4
      neufuse
      146
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!