简体   繁体   中英

Output next 35 days from input date

I am trying to print the next 35 days of a particular date. Here is my function:

$randomdate = '01-01-2015';
$a=0;
while($a<35){
 $date = date("Y-m-d", strtotime("+1 day", strtotime($randomdate)));
 $a++; 
 $randomdate =   $date; 
}

But this prints only 30 days . Its does not get incremented to next date if month changes. Where did I go wrong ?

You can do like this

<?php
$start_date = '25-02-2016';
$number_of_dates = 10;
$dates = array();
for($i=1;$i<=$number_of_dates;$i++){
  $date = date('Y-m-d', strtotime("$start_date +$i days"));
  echo "\n".$date;
  $dates[] = $date;  
}
?>

Check here : https://eval.in/539120

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