php 計算 時間段的天數

            $firstday = date("Y-m-d H:i:s",time());//當前日期
            $timestamp=strtotime($firstday);//當前日期時間戳
            $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"));//上個月結束的日期
            $stimestamp = strtotime($firstday);
            $etimestamp = strtotime($lastday);
            // 計算日期段內有多少天
            $days = ($etimestamp-$stimestamp)/86400+1;
            // 保存天天日期
            $date = array();
            for($i=0; $i<$days; $i++){
                $date[] = date('Y-m-d', $stimestamp+(86400*$i));
            }ast

相關文章
相關標籤/搜索