php 本周、上周、本月、上月

public function test(){

        //上周开始时间(上周开始时间)
        $startDate_last_week=date("Y-m-d 00:00:00",mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
        var_dump($startDate_last_week);
        //本周对应上周时间(上周结束时间)
        $endDate_last_week = date("Y-m-d 23:59:59",strtotime("-1 week"));
        var_dump($endDate_last_week);
        //上月开始时间(上月开始时间)
        $startDate_last_month = date("Y-m-d H:i:s",mktime(0,0,0,date("m")-1,1,date("Y")));
        var_dump($startDate_last_month);
        //本月对应上月时间(上月结束时间)
        $endDate_last_month = date("Y-m-d 23:59:59",strtotime("-1 month"));
        var_dump($endDate_last_month);
        //本周开始时间
        $w = date("w");
        $startDate_this_week = date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$w+1,date("Y")));
        var_dump($startDate_this_week);
        $endDate_this_week=date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('d')-date('w')+7,date('Y')));
        var_dump($endDate_this_week);
        //本月开始时间
        $startDate_this_month = date("Y-m-d H:i:s",mktime(0,0,0,date("m"),1,date("Y")));
        var_dump($startDate_this_month);
        $endDate_this_month = date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('t'),date('Y'))-1);
        var_dump($endDate_this_month);

        //根据某个指定时间查出其上月时间
    $last_start_time = date("Y-m",strtotime("-1 month",strtotime($start_time)));
            $firstday_one = $last_start_time.'-'.'01 00:00:00';
            $lastday_one = date('Y-m-d 23:59:59', strtotime("$firstday_one +1 month -1 day"));
            $s_start_time = date('Y-m-d 23:59:59',strtotime($firstday_one));
            $s_end_time = date('Y-m-d 23:59:59',strtotime($lastday_one));
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值