3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $date = date("Y-m-d"); //w:星期几,0-6 //取得指定时间所属月的第一天 $firstday = date("Y-m-01",strtotime($date)); //取得指定时间所属月的最后一天 $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day")); //取得指定时间所属月的第一天是星期几 $w = date("w",strtotime($firstday)); //需要往前多取的天数(根据画面显示需要得出) $days_up = $w; //取得指定时间所属月的最后一天是星期几 $w = date("w",strtotime($lastday)); //需要往后多取的天数(根据画面显示需要得出) $days_down = 6 - $w; $start_date = date("Y-m-d",strtotime($firstday) - 86400 * $days_up); $end_date = date("Y-m-d",strtotime($lastday) + 86400 * $days_down); $days = (int) ((strtotime($end_date) - strtotime($start_date))/86400); $info = array( 'start_date'=>$start_date, 'end_date'=>$end_date, 'days'=>$days ); print_r($info);
Output for 4.3.0 - 7.1.0
Array ( [start_date] => 2014-09-28 [end_date] => 2014-11-01 [days] => 34 )