I'm trying and still wondering, how I can get an array which contains all of the dates in the current month, it should contain all of the dates in format: year-month-day. Thanks for your help!
a simple function to return such an array could look like this:
function range_date($first, $last) {
$arr = array();
$now = strtotime($first);
$last = strtotime($last);
while($now <= $last ) {
$arr[] = date('Y-m-d', $now);
$now = strtotime('+1 day', $now);
}
return $arr;
}
if needed, you can improve it by changing the step (+1 day
) and the output format (Y-m-d
) into optional parameters.
Try:
// for each day in the month
for($i = 1; $i <= date('t'); $i++)
{
// add the date to the dates array
$dates[] = date('Y') . "-" . date('m') . "-" . str_pad($i, 2, '0', STR_PAD_LEFT);
}
// show the dates array
var_dump($dates);
How about this:
$list=array();
for($d=1; $d<=31; $d++)
{
$time=mktime(12, 0, 0, date('m'), $d, date('Y'));
if (date('m', $time)==date('m'))
$list[]=date('Y-m-d', $time);
}
var_dump($list);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With