php 时间戳 总结 今日,昨日,上周,本周,最近三个月,上季,本季,去年,最近七天,今年,最近三十天
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 时间戳 总结 今日,昨日,上周,本周,最近三个月,上季,本季,去年,最近七天,今年,最近三十天的更多相关文章
- JS函数 计算 今日,昨日,本周,上周,本月
最近有个功能会进行数据的筛选于是便写了几个快速计算 今日,昨日,本周,上周,本月 范围的function 以便以后遇到同样的问题可以直接进行复用,代码如下: /* *获取今日的起始和结束时间 *返回值 ...
- Oracle 查询今天、昨日、本周、本月和本季度的所有记录
Oracle 查询今日.昨日.本周.本月和本季度的所有记录 字段类型为date 今日 select * from 表名 where to_char(字段名,'dd')=to_char(sysdate, ...
- Datediff的使用(统计本日,昨日,本周,本月)
//统计本日,昨日,本周,本月添加的产品总数 //日期 DateTime DT = DateTime.Now; string day=DT.Date.ToS ...
- Oracle 获取本周、本月、本季、本年的第一天和最后一天
Oracle 获取本周.本月.本季.本年的第一天和最后一天 --本周 select trunc(sysdate, 'd') + 1 from dual; select trunc(sysdate, ' ...
- php 获取今日、昨日、本周,上周、本月,上月,季度的起始时间戳和结束时间戳的方法
php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日.上周.本月的起始 ...
- JS 获取 今日、昨日、本周、本月、本季度、本年、上月、上周、上季度、去年
/** * 日期范围工具类 */ var dateRangeUtil = (function () { /*** * 获得当前时间 */ this.getCurrentDate = function ...
- PHP获取今日、昨日、本周、上周、本月、上月、本季、上季、今年、去年
//今天开始$beginToday = date('Y-m-d 00:00:00', time());//今天结束$endToday = date('Y-m-d 23:59:59', time()); ...
- SQL 查询--日期条件(今日、昨日、本周、本月。。。) (转)
主要用到sql 函数 DATEDIFF(datepart,startdate,enddate) sql 语句,设 有 数据库表 tableA(日期字段ddate) ——查询 今日 select * f ...
- JavaScript(js)获取本周,本月,本季,本年,上月,上周,上季,去年,上二周,上二月的时间段的代码
function dateChange(name){ var beginTimeObject = document.getElementById("beginTime"); var ...
随机推荐
- 为什么PCI-e比SATA快这么多?
PCIe协议和SATA协议都是分层协议,分为物理层,数据链路层,传输层,命令层和应用层. 硬件工程师主要关注物理层.数据链路层和传输层.所有CMD/data由应用层和命令层打下来,每向下走一层,多一层 ...
- hiho #1079 : 离散化
描述 小Hi和小Ho在回国之后,重新过起了朝7晚5的学生生活,当然了,他们还是在一直学习着各种算法~ 这天小Hi和小Ho所在的学校举办社团文化节,各大社团都在宣传栏上贴起了海报,但是贴来贴去,有些海报 ...
- super返回不过来
class Fruit { String color = "未确定颜色"; //定义一个方法,该方法返回调用该方法的实例 public Fruit getT ...
- SCU 4440 Rectangle 2015年四川省赛题
题目链接:http://acm.scu.edu.cn/soj/problem/4440/ 题目大意:给一个n*m的方格,求周长小于等于k的矩形有多少个. 解题思路:我之前直接暴力,显然超时,所以后来发 ...
- 【数学】【NOIp2012】同余方程 题解 以及 关于扩展欧几里得与同余方程
什么是GCD? GCD是最大公约数的简称(当然理解为我们伟大的党也未尝不可).在开头,我们先下几个定义: ①a|b表示a能整除b(a是b的约数) ②a mod b表示a-[a/b]b([a/b]在Pa ...
- hdu 4608 I-number 大整数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4608 #include <cstdio> #include <cmath> # ...
- hdu 4640 Island and study-sister(状态压缩dp)
先处理前两个学长到达各个点所需要的最少时间,在计算前两个学长和最后一个学长救出所有学妹的最少时间. #include<stdio.h> #include<string.h> # ...
- Invocation of init method failed; nested exception is org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl
严重: Exception sending context initialized event to listener instance of class org.springframework.we ...
- 自我理解foreach工作原理
很多时候我们在使用for循环遍历一个数组的时候,我们都知道可以通过下标的索引找到当前数组中所对应的数据.这只对于简单的数组或集合,如果我们存储的数据不止只有数据项,还有一个标识项,就如同Has ...
- [CSS3] Text ellipsis
Link: http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_text-overflow div{ white-space: now ...