Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a weekly report?

Tags:

date

php

i was able to generate a weekly report using some date function. The table looks like

-------------------------------------------------------------------------
week |Sunday  |Monday  |Tuesday |Wednesday |Thursday |Friday  |Saturday |
     |July 21 |July 22 |July 23 |July 24   |July 25  |July 26 |July 27  |
-------------------------------------------------------------------------

but whenever the current week consists of 2 months, like end of July and start of August. i am unable to find the current week. The table looks like

-------------------------------------------------------------------------
week |Sunday  |Monday  |Tuesday |Wednesday |Thursday |Friday  |Saturday |
     |July 28 |July 29 |July 30 |July 31   |July 32  |July 33 |July 34  |
-------------------------------------------------------------------------

please help. The result should look like

--------------------------------------------------------------------------
week |Sunday  |Monday  |Tuesday |Wednesday |Thursday |Friday   |Saturday |
     |July 28 |July 29 |July 30 |July 31   |August 1 |August 2 |August 3 |
--------------------------------------------------------------------------
like image 337
Sushant Aryal Avatar asked Dec 16 '25 17:12

Sushant Aryal


1 Answers

I assume you have the first day of the week as a starting point?

Then use phps stringtotime to easily progress in days:

<?php
   $startOfWeek = date("Y-m-d", strtotime("Monday this week"));

   for ($i=0; $i<7;$i++){
       echo date("l, d M", strtotime($startOfWeek . " + $i day"))."<br />";
   }
?>

Output:

Monday, 29 Jul
Tuesday, 30 Jul
Wednesday, 31 Jul
Thursday, 01 Aug
Friday, 02 Aug
Saturday, 03 Aug
Sunday, 04 Aug

format as required.

Update to your Question:

//find week start
$weekstart = date("Y-m-d", strtotime("Monday this week"))   ;
echo $weekstart; 

strtotime is pretty flexible .

like image 58
dognose Avatar answered Dec 19 '25 11:12

dognose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!