0

How to show list of week and date range of week in 1 year using php Like this:https://www.epochconverter.com/weeks/2017

1 Answers1

0

Try this, and a little creativity will improve it.

function getStartAndEndDate($week, $year) {
  $dto = new DateTime();
  $dto->setISODate($year, $week);
  $ret['week_start'] = $dto->format('Y-m-d');
  $dto->modify('+6 days');
  $ret['week_end'] = $dto->format('Y-m-d');
  return $ret;
} ?>
    <table>
        <tr>
            <th>Week Number</th>
            <th>From Date</th>
            <th>To Date</th>
        </tr>
<?php 
for($i=1; $i<=52; $i++){
    $week_array = getStartAndEndDate($i,2017);
    //print_r($week_array); 
    echo "<tr>
            <td>Week $i </td>
            <td>".$week_array['week_start']."</td>
            <td>".$week_array['week_end']."</td>
        </tr>"; 
} ?>

</table>
Josiah
  • 118
  • 10