Thursday, 2 February 2017

How to get the current month day list using dynamic current month and year

How to get the current month day list using dynamic current month and year


<?php

$year = date('Y');
$month = date('m');

$start_date = "01-".$month."-".$year;
$start_time = strtotime($start_date);


$end_time = strtotime("+1 month", $start_time);

for($i=$start_time; $i<$end_time; $i+=86400)
{
   $list[] = date('d',$i);
}

print_r($list);

?>

Result: 
Array ( [0] => 01 [1] => 02 [2] => 03 [3] => 04 [4] => 05 [5] => 06 [6] => 07 [7] => 08 [8] => 09 [9] => 10 [10] => 11 [11] => 12 [12] => 13 [13] => 14 [14] => 15 [15] => 16 [16] => 17 [17] => 18 [18] => 19 [19] => 20 [20] => 21 [21] => 22 [22] => 23 [23] => 24 [24] => 25 [25] => 26 [26] => 27 [27] => 28 )