獲取同比上月的日期 沒有取上月最後一天

/**
 * 獲取同比上月的日期
 * 沒有的取上月最後一天
 * @param $date
 * @return string
 */
function getTongBiDate($date){
    $time = strtotime($date);
    $start_date = date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', $time))));
    // 上個月的天數
    $lm_days = date('t', strtotime($start_date));
    //本月查的日期
    $day = date('d', $time);
    if($lm_days < $day){
        $tb_date = date('Y-m', strtotime($start_date))."-".$lm_days;
    }else{
        $tb_date = date('Y-m-d', strtotime('-1 month', $time));
    }
    return $tb_date;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章