如何用PHP 获取今天之前,本周之前,本月之前,本年之前,今天,本周,本月,本年的数据呢

如何用PHP 获取今天之前,本周之前,本月之前,本年之前,今天,本周,本月,本年的数据呢,第1张

/今天/

select  from 表名 where to_days(时间字段) = to_days(now());

/昨天/

select  from 表名 where to_days(now())-to_days(时间字段) = 1;

/近7天/

select  from 表名 where date_sub(curdate(), interval 7 day) <= date(时间字段);

/查询距离当前现在6个月的数据/

select  from 表名 where 时间字段 between date_sub(now(),interval 6 month) and now();

/查询当前这周的数据/

select  from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now());

/查询上周的数据/

select  from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now())-1;

/查询当前月份的数据/

select  from 表名 where date_format(时间字段,'%Y-%m')=date_format(now(),'%Y-%m');

/查询上个月的数据/

select  from 表名 where date_format(时间字段,'%Y-%m')=date_format(date_sub(curdate(), interval 1 month),'%Y-%m');

其它获取类似以上的代码显示

给你个例子,是我这几天在开发过程中正在用的

SELECT DATE_FORMAT(JL_RQ,'%Y-%m') sj,SUM(jl_spsl) sl FROM sp_xs_lsjl WHERE JL_SPM='1' AND JL_RQ BETWEEN '2017-01-01' AND '2017-12-12' GROUP BY sj ORDER BY sj;

以上就是关于如何用PHP 获取今天之前,本周之前,本月之前,本年之前,今天,本周,本月,本年的数据呢全部的内容,包括:如何用PHP 获取今天之前,本周之前,本月之前,本年之前,今天,本周,本月,本年的数据呢、mysql 如何获取每周的第一天、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9354188.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存