1

I am doing weekly report excel file export. I have $dateFrom and $dateTo.

$dateForm = "2021-07-26";
$dateTo = "2021-08-13";

I want to get by week based on those two dates. Monday to Sunday is one week and I want to get the dateForm and dateTo for that week.

The result I want to display is:

For example :

dateForm      dateTo     
----------   ----------
2021-07-26   2021-08-01
2021-08-02   2021-08-08
2021-08-09   2021-08-13

Thanks.

İsmail Y.
  • 3,579
  • 5
  • 21
  • 29
  • 4
    What have you tried? Hint: With something like `date("W", strtotime($yourdate))` you can get the week of the year. – KIKO Software Aug 13 '21 at 07:44
  • You should try to do it with dateTime diff object - https://stackoverflow.com/questions/45682106/php-datetime-difference-hours-days-weeks-months – Andrii Sukhoi Aug 13 '21 at 07:50

1 Answers1

1

As @KIKO Software said in comments, You can use date("W", strtotime($yourdate)) to get the week of the year.

Check this code:

<?php

$startDate = "2021-07-26";
$endDate = "2021-08-26";

$numberOfWeeks = (int)date("W", strtotime($endDate)) - (int)date("W", strtotime($startDate));

echo $numberOfWeeks;

?>
BadPiggie
  • 5,471
  • 1
  • 14
  • 28