When you use strtotime , your week should be double-digit . You must add zero if the week is less than 10 before the for loop.
if($week < 10) { $week = '0'. $week; } for($day = 1; $day <= 7; $day++) {
In addition, during the year only 52 weeks, the condition at the beginning should be.
if($week > 52) { $year++; $week = 1; } elseif($week < 1) {
Full code:
<?php $year = (isset($_GET['year'])) ? $_GET['year'] : date("Y"); $week = (isset($_GET['week'])) ? $_GET['week'] : date('W'); if($week > 52) { $year++; $week = 1; } elseif($week < 1) { $year--; $week = 52; } ?> <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week == 52 ? 1 : 1 + $week).'&year='.($week == 52 ? 1 + $year : $year); ?>">Next Week</a> <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week == 1 ? 52 : $week -1).'&year='.($week == 1 ? $year - 1 : $year); ?>">Pre Week</a> <table border="1px"> <tr> <td>Employee</td> <?php if($week < 10) { $week = '0'. $week; } for($day= 1; $day <= 7; $day++) { $d = strtotime($year ."W". $week . $day); echo "<td>". date('l', $d) ."<br>". date('d M', $d) ."</td>"; } ?> </tr> </table>
source share