if($time=="今日"){
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
$begin = Date("Y-m-d",$beginToday);
$end = Date("Y-m-d",$endToday);
}else if($time=="昨日"){
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
$begin = Date("Y-m-d",$beginYesterday);
$end = Date("Y-m-d",$endYesterday);
}else if($time=="上周"){
$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'));
$begin = Date("Y-m-d",$beginLastweek);
$end = Date("Y-m-d",$endLastweek);
}else if($time=="本周"){
//判断当天是星期几,0表星期天,1表星期一,6表星期六
$w_day=date("w",time());
//php处理当前星期时间点上,根据当天是否为星期一区别对待
if($w_day=='1'){
$cflag = '+0';
$lflag = '-1';
}else {
$cflag = '-1';
$lflag = '-2';
}
//本周一零点的时间戳
$frist = strtotime(date('Y-m-d',strtotime("$cflag week Monday", time())));
$begin = Date("Y-m-d",$frist);
$end = Date("Y-m-d",time());
}else if($time=="本月"){
$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
$begin = Date("Y-m-d",$beginThismonth);
$end = Date("Y-m-d",$endThismonth);
}else if($time=="上月"){
$beginLastmonth=mktime(0,0,0,date('m')-1,1,date('Y'));
$endLastmonth=mktime(23,59,59,date('m')-1,date('t'),date('Y'));
$begin = Date("Y-m-d",$beginLastmonth);
$end = Date("Y-m-d",$endLastmonth);
}else if($time=="最近三个月"){
$beginThreemonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
$endThreemonth=mktime(23,59,59,date('m')-3,date('t'),date('Y'));
$begin = Date("Y-m-d",$beginThreemonth);
$end = Date("Y-m-d",$endThreemonth);
}else if($time=="本季"){
$begin = date('Y-m-d', mktime(0, 0, 0,$season*3-3+1,1,date('Y')));
$end = date('Y-m-d', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y')));
}else if($time=="上季"){
$season = ceil((date('n'))/3);//当月是第几季度
$begin = date('Y-m-d', mktime(0, 0, 0,$season*3-3-3+1,1,date('Y')));
$end = date('Y-m-d', mktime(23,59,59,$season*3-3,date('t',mktime(0,0,0,$season*3,1,date("Y"))),date('Y')));
}else if($time=="今年"){
$begin = date('Y',time()). '-' ."01-01";
$end = date('Y',time()). '-' ."12-31";
}else if($time=="去年"){
$d=strtotime('-1 years');
$begin = date('Y',$d)."-01-01";
$end = date('Y',$d)."-12-31";
}else if($time=="最近七天"){
$begin = date('Y-m-d', strtotime('-7 days'));
$end = date('Y-m-d',time());
}else if($time=="最近三十天"){
$begin = date('Y-m-d', strtotime('-30 days'));
$end = date('Y-m-d',time());
}

php 时间戳 总结 今日,昨日,上周,本周,最近三个月,上季,本季,去年,最近七天,今年,最近三十天的更多相关文章

  1. JS函数 计算 今日,昨日,本周,上周,本月

    最近有个功能会进行数据的筛选于是便写了几个快速计算 今日,昨日,本周,上周,本月 范围的function 以便以后遇到同样的问题可以直接进行复用,代码如下: /* *获取今日的起始和结束时间 *返回值 ...

  2. Oracle 查询今天、昨日、本周、本月和本季度的所有记录

    Oracle 查询今日.昨日.本周.本月和本季度的所有记录 字段类型为date 今日 select * from 表名 where to_char(字段名,'dd')=to_char(sysdate, ...

  3. Datediff的使用(统计本日,昨日,本周,本月)

    //统计本日,昨日,本周,本月添加的产品总数 //日期            DateTime DT = DateTime.Now;            string day=DT.Date.ToS ...

  4. Oracle 获取本周、本月、本季、本年的第一天和最后一天

    Oracle 获取本周.本月.本季.本年的第一天和最后一天 --本周 select trunc(sysdate, 'd') + 1 from dual; select trunc(sysdate, ' ...

  5. php 获取今日、昨日、本周,上周、本月,上月,季度的起始时间戳和结束时间戳的方法

    php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日.上周.本月的起始 ...

  6. JS 获取 今日、昨日、本周、本月、本季度、本年、上月、上周、上季度、去年

    /** * 日期范围工具类 */ var dateRangeUtil = (function () { /*** * 获得当前时间 */ this.getCurrentDate = function ...

  7. PHP获取今日、昨日、本周、上周、本月、上月、本季、上季、今年、去年

    //今天开始$beginToday = date('Y-m-d 00:00:00', time());//今天结束$endToday = date('Y-m-d 23:59:59', time()); ...

  8. SQL 查询--日期条件(今日、昨日、本周、本月。。。) (转)

    主要用到sql 函数 DATEDIFF(datepart,startdate,enddate) sql 语句,设 有 数据库表 tableA(日期字段ddate) ——查询 今日 select * f ...

  9. JavaScript(js)获取本周,本月,本季,本年,上月,上周,上季,去年,上二周,上二月的时间段的代码

    function dateChange(name){ var beginTimeObject = document.getElementById("beginTime"); var ...

随机推荐

  1. Oracle 11g ORA-12514:TNS:监听程序当前无法识别连接描述符中请求的服务

    1. 找到listener.ora监听文件,具体位置:D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora 2 ...

  2. Jump Game —— LeetCode

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  3. workflow4.0学习资料

    http://www.cnblogs.com/foundation/archive/2010/04/03/1703809.html 2篇说明: WF4 Bata 2 WF4.0 RC 对比 Beta2 ...

  4. Windows下移动硬盘无法识别但是Mac下可以识别

    今天遇到一个问题,具体如下: 在Mac下正常使用的移动硬盘,在Windows下无法识别,打开显示"磁盘结构损坏且无法读取" 分析:Mac下既然能够正常使用,那么硬盘就应该是正常的, ...

  5. TXT四则运算计算器

    基本思想:使用getline函数从TXT文件中依次读出中缀表达式,将其转为后缀表达式后计算结果,并与用户结果比对. 整数.分数.小数的处理:将小数和整数都视为默认分母为1的分数.建立分数类,在中缀转换 ...

  6. [Theano] Theano初探

    1. Theano用来干嘛的? Theano was written at the LISA lab to support rapid development of efficient machine ...

  7. python 解析 配置文件

    资料: https://docs.python.org/3/library/configparser.html 环境 python 3.4.4 RawConfigParser方式 example.cf ...

  8. 转载:Ununtu下中文乱码解决方案

    转载: 添加中文字符编码: $sudo vim /var/lib/locales/supported.d/local #添加下面的中文字符集 zh_CN.GBK GBK zh_CN.GB2312 GB ...

  9. Ken Norton和软件工程师打交道的10个秘诀

    How to work with software engineers - by Ken Norton Deflect praise Absorb blame Sweat the details In ...

  10. HDU 4622 多校第三场1002 后缀自动机

    比赛的时候我是用后缀数组的,但是T了. 赛后看了解题报告说,后缀数组貌似是卡你常数的时间,我算了下复杂度O(T * Q * n).这是10 ^ 8,但是考虑到每次询问的时候都要重新构造字符,所以那个n ...