php如何求上一个月月初至月末

php如何求上一个月月初至月末,第1张

由于php内置时间函数 strtotime 在求上个月这个功能上存在bug,所以放弃不用了……

上个自己写的临时用的,楼主看看:

$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));

echo 'lastStartDay = '$lastStartDay;

echo '<br/>';

echo 'lastEndDay = '$lastEndDay;

<php 

    $time = time();  

      

    / 

      计算上一个月的今天,如果上个月没有今天,则返回上一个月的最后一天 

      @param type $time 

      @return type

      >

以上就是关于php如何求上一个月月初至月末全部的内容,包括:php如何求上一个月月初至月末、如何使用PHP计算上一个月的今天、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9295739.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存