简体   繁体   中英

How to display next 5 days in php

How would i display the next 5 days in php?

18/03/2012

19/03/2012

20/03/2012

21/03/2012

22/03/2012

for ($i = 1; $i <= 5; $i++) {
  echo date('d/m/Y', strtotime('+'.$i.' day')) ."<br />";
}
for ($i = 1; $i <= 5; $i++)
    echo date("d/m/Y", time() + 86400 * $i) . "<br>";

Another way to do this:

$cursor=new DateTime("now",new DateTimeZone("America/Chicago"));

for ($i=1;$i<=5;$i++) {
    $cursor->modify("+1 day");
    echo "\n".$cursor->format("d/m/Y");
}
for ($i = 1; $i <= 5; $i++) {
    var_dump(date('d/m/Y', strtotime("+ $i days")));
}
$day = 60 * 60 * 24;
$today = time();

for($i = 1; $i <= 5; $i++)
{
    echo date("d/m/Y", $today + $day * $i) + "\n";
}
<?php

$dt = new DateTime();
for($i = 1; $i <= 5; $i++) {
    $dt->add(new DateInterval('P1D'));
    echo $dt->format('d/m/Y'), "\n\n";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM