Carbon获取上个月第一天和最后一天

Carbon获取指定月份

tips1:本月第一天和本月最一天
Carbon::now()->startOfMonth()->toDateTimeString();
Carbon::now()->endOfMonth()->toDateTimeString();

tips2:上个月第一天
$firstOfMonth = new Carbon('first day of last month');
$firstOfMonth->startOfMonth()->toDateTimeString();

tips3:上个月最后一天
$lastOfMonth = new Carbon('last day of last month');
$lastOfMonth->endOfMonth()->toDateTimeString();

tips4:判断指定时间是否在本月内
Carbon::parse($timestamp)->isCurrentMonth()

tips5:判断指定时间是否在上个月内
Carbon::parse($timestamp)->isLastMonth()

原文地址:https://www.cnblogs.com/wangsky/p/14596766.html