1

I got this code from here: Creation of weekly calender in php

My question is, how do I make it end up to Saturday only?

    <?php
    $dt = new DateTime;
    if (isset($_GET['year']) && isset($_GET['week'])) {
        $dt->setISODate($_GET['year'], $_GET['week']);
    } else {
        $dt->setISODate($dt->format('o'), $dt->format('W'));
    }
    $year = $dt->format('o');
    $week = $dt->format('W');
?>

<center>
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week-1).'&year='.$year; ?>" style="padding-right: 600px">Previous Week</a> <!--Previous week-->
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week+1).'&year='.$year; ?>" style="padding-left: 600px">Next Week</a> <!--Next week-->
</center>

<table border="1" style="text-align: center" align="center">
    <col width="100px" />
    <col width="200px" />
    <col width="200px" />
    <col width="200px" />
    <col width="200px" />
    <col width="200px" />
    <col width="200px" />
    <tr>
        <td>Time</td>
    <?php
        do {
            echo "<td>" . $dt->format('l') . "<br>" . $dt->format('F d') . "</td>\n";
            $dt->modify('+1 day');
        } while ($week == $dt->format('W'));
    ?>
Community
  • 1
  • 1
rekt
  • 65
  • 1
  • 11

1 Answers1

0

Solved by replacing this:

do {
    echo "<td>" . $dt->format('l') . "<br>" . $dt->format('F d') . "</td>\n";
    $dt->modify('+1 day');
} while ($week == $dt->format('W'));

to this:

for($day=1;$day<=6;$day++){
    echo "<td>" . $dt->format('l') . "<br>" . $dt->format('F d') . "</td>\n";
    $dt->modify('+1 day');
}

:D

Ekin
  • 1,957
  • 2
  • 31
  • 45
rekt
  • 65
  • 1
  • 11
  • your answer helped me ! how to get from sunday to saturday with your getting monday to saturday can you please help me – gig Jun 10 '20 at 09:48