-1

My current script shows all dates of current month but I want total 30 dates including next months date:

<?php        

$dateToday = Date("d");             
$currentMonthDigits = Date("m");                
$currentMonthText = Date("M");              
$currentYear = Date("Y");                        

for ( $i=$dateToday; $i<32; $i++ ) {
  $theday = date('d', mktime(0,0,0,0,$i,2000)); 
  if($theday == $dateToday)                     
    echo "<option value='$currentYear-$currentMonthDigits-$theday'>Today</option>";
  else
    echo "<option value='$currentYear-$currentMonthDigits-$theday'>$theday $currentMonthText $currentYear</option>";
}
?> 
methode
  • 5,348
  • 2
  • 31
  • 42

2 Answers2

1
$date = time();
for ( $i=$dateToday; $i<32; $i++ ) {
    echo date("Y-m-d", $date) . " " .  date("d M Y", $date) . "\n";
    $date = strtotime(date("Y-m-d", $date) . " +1 day" );
}

output

2015-07-06 06 Jul 2015
...
2015-07-30 30 Jul 2015
2015-07-31 31 Jul 2015
2015-08-01 01 Aug 2015
2015-08-02 02 Aug 2015
...
2015-08-06 06 Aug 2015

Demo

splash58
  • 26,043
  • 3
  • 22
  • 34
0
$dateToday = date('Y-m-d'); 
$date30th = date("Y-m-d",strtotime("+30 days"));
$dateRanges = date_range($dateToday,$date30th); 
$output = '';
foreach($dateRanges as $dateRange) {
    $output .= '<option value='.$dateRange.'>'.$dateRange.'</option>';
}
echo '<select>'.$output.'</select>';
function date_range($first, $last, $step = '+1 day', $output_format = 'd/m/Y' ) {

    $dates = array();
    $current = strtotime($first);
    $last = strtotime($last);

    while( $current <= $last ) {

        $dates[] = date($output_format, $current);
        $current = strtotime($step, $current);
    }

    return $dates;
}

You'll get some hint from stackoverflow itself, check this link - https://stackoverflow.com/a/9225875/639293

Community
  • 1
  • 1
Kamal Joshi
  • 1,298
  • 3
  • 25
  • 45