0

Today I found this function that says how many days were in a month cal_days_in_month(). But what I am wanting to do is list all the days into array, something like this.

$days = array(
"2012-11-01","2012-12-01","2012-13-01"...etc
)

Could someone point me into the right direction?

Kind regards Frank!

2 Answers 2

2
$start    = new DateTime('first day of this month');
$end      = new DateTime('first day of next month');
$interval = DateInterval::createFromDateString('1 day');
$period   = new DatePeriod($start, $interval, $end);

foreach ($period as $dt)
{
  echo $dt->format("l Y-m-d") . PHP_EOL;
}

See it in action

Reference

Sign up to request clarification or add additional context in comments.

Comments

0
 $fromdate=strtotime(date("Y-m-d",mktime(0, 0, 0, $month, '01', $year)));
    $todate=strtotime(date("Y-m-t",mktime(0, 0, 0, $month, '01', $year)));

        for($i=$fromdate;$i<=$todate;$i++)
        {
        $i=$i+84600;
        echo     $nextdate[]=date('Y-m-d',$i);
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.