3v4l.org

run code in 300+ PHP versions simultaneously
<?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 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Array ( [start_date] => 2014-09-28 [end_date] => 2014-11-01 [days] => 34 )

preferences:
241.9 ms | 406 KiB | 352 Q