function getNextMonthDays($date){
$timestamp=strtotime($date);
$arr=getdate($timestamp);
// var_dump($arr);
if($arr['mon'] == 12){
$year=$arr['year'] +1;
$month=$arr['mon'] -11;
$firstday=$year.'-0'.$month.'-01';
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
}else{
$firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)+1).'-01'));
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
}
return array($firstday,$lastday);
}
var_dump(getNextMonthDays('2017-11-15 12:12:12'));
image.png
//获取上月月初月末时间戳
function last_month_start_end(){
$arr = [];
$thismonth = date('m');
$thisyear = date('Y');
if ($thismonth == 1) {
$lastmonth = 12;
$lastyear = $thisyear - 1;
} else {
$lastmonth = $thismonth - 1;
$lastyear = $thisyear;
}
$lastStartDay = $lastyear . '-' . $lastmonth . '-1';
$lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)).' 23:59:59';
$arr['last_month_start'] = strtotime($lastStartDay);
$arr['last_month_end'] = strtotime($lastEndDay);
return $arr;
}
网友评论