欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP获取今日本月上月

程序员文章站 2022-07-23 23:48:26
//今日 $today=mktime(0,0,0,date('m'),date('d'),date('Y'));...
//今日
$today=mktime(0,0,0,date('m'),date('d'),date('Y')); 


//本月月初时间戳
$month_start=mktime(0, 0 , 0,date("m"),1,date("Y"));

//上月月初时间戳、上月月未时间戳
$lastmonth_start=mktime(0,0,0,date('m')-1,1,date('Y'));
$lastmonth_end=mktime(0,0,0,date('m'),1,date('Y'))-24*3600;


//PHP获取今日开始时间戳和结束时间戳
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;


//php获取昨日起始时间戳和结束时间戳
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

//php获取上周起始时间戳和结束时间戳
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));

//php获取本月起始时间戳和结束时间戳
$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
<?php  
echo "今天:".date("Y-m-d")."<br>";       
echo "昨天:".date("Y-m-d",strtotime("-1 day")), "<br>";       
echo "明天:".date("Y-m-d",strtotime("+1 day")). "<br>";    
echo "一周后:".date("Y-m-d",strtotime("+1 week")). "<br>";       
echo "一周零两天四小时两秒后:".date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")). "<br>";       
echo "下个星期四:".date("Y-m-d",strtotime("next Thursday")). "<br>";       
echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>";       
echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>";       
echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>";       
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";      
?>
< ?php
/*
*按今天,本周,本月,本季度,本年,全部查询预约单数据
* $day 代表查询条件 $cid 代表 公司id
*返回array $data 查询条件 数组
*/
class ReserveModel extends BaseModel {
    public
    function find_createtime($day, $cid) {
        //查询当天数据
        if ($day == 1) {
            $today = strtotime(date('Y-m-d 00:00:00'));
            $data['cid'] = $cid;
            $data['createtime'] = array('egt', $today);
            return $data;
            //查询本周数据
        } else if ($day == 2) {
            $arr = array();
            $arr = getdate();
            $num = $arr['wday'];
            $start = time() - ($num - 1) * 24 * 60 * 60;
            $end = time() + (7 - $num) * 24 * 60 * 60;
            $data['cid'] = $cid;
            $data['createtime'] = array('between', array($start, $end));
            return $data;
            //查询本月数据
        } else if ($day == 3) {
            $start = strtotime(date('Y-m-01 00:00:00'));
            $end = strtotime(date('Y-m-d H:i:s'));
            $data['cid'] = $cid;
            $data['createtime'] = array('between', array($start, $end));
            return $data;
            //查询本季度数据
        } else if ($day == 4) {
            $month = date('m');
            if ($month == 1 || $month == 2 || $month == 3) {
                $start = strtotime(date('Y-01-01 00:00:00'));
                $end = strtotime(date("Y-03-31 23:59:59"));
            }
            elseif($month == 4 || $month == 5 || $month == 6) {
                $start = strtotime(date('Y-04-01 00:00:00'));
                $end = strtotime(date("Y-06-30 23:59:59"));
            }
            elseif($month == 7 || $month == 8 || $month == 9) {
                $start = strtotime(date('Y-07-01 00:00:00'));
                $end = strtotime(date("Y-09-30 23:59:59"));
            } else {
                $start = strtotime(date('Y-10-01 00:00:00'));
                $end = strtotime(date("Y-12-31 23:59:59"));
            }
            $data['cid'] = $cid;
            $data['createtime'] = array('between', array($start, $end));
            return $data;
            //查询本年度数据
        } else if ($day == 5) {
            $year = strtotime(date('Y-01-01 00:00:00'));
            $data['cid'] = $cid;
            $data['createtime'] = array('egt', $year);
            return $data;
            //全部数据
        } else {
            $data['cid'] = $cid;
            return $data;
        }
    }
}
? >