How to show list of week and date range of week in 1 year using php Like this:https://www.epochconverter.com/weeks/2017
Asked
Active
Viewed 266 times
0
-
Look at the date function. http://php.net/manual/fr/function.date.php#106974 – Xenofexs Jun 01 '17 at 07:57
-
1please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – user1810087 Jun 01 '17 at 07:57
1 Answers
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