how to show number of week and show date range in php

China☆狼群 提交于 2019-12-12 04:13:25

问题


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:


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>


来源:https://stackoverflow.com/questions/44301682/how-to-show-number-of-week-and-show-date-range-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!