查询当前这周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());
查询上周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;
查询当前月份的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')
查询距离当前现在6个月的数据
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
查询上个月的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')
select * from `user` where DATE_FORMAT(pudate,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') ;
select * from user where WEEKOFYEAR(FROM_UNIXTIME(pudate,'%y-%m-%d')) = WEEKOFYEAR(now())
select *
from user
where MONTH(FROM_UNIXTIME(pudate,'%y-%m-%d')) = MONTH(now())
select *
from [user]
where YEAR(FROM_UNIXTIME(pudate,'%y-%m-%d')) = YEAR(now())
and MONTH(FROM_UNIXTIME(pudate,'%y-%m-%d')) = MONTH(now())
select *
from [user]
where pudate between 上月最后一天
and 下月第一天
查询当前这周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());
查询上周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;
查询当前月份的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')
查询距离当前现在6个月的数据
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
查询上个月的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')
原文出处:http://blog.163.com/hubeixl@126/blog/static/4991486220106154756221/
分享到:
相关推荐
查询上个月的数据同样可以通过比较月份的方式来实现,只需要将当前时间减去一个月的时间差: ```sql SELECT name, submittime FROM enterprise WHERE date_format(submittime, '%Y-%m') = date_format(DATE_SUB...
### MySQL查询本周、上周与上个月份的相关知识点 在日常工作中,我们经常需要根据不同的时间范围来筛选数据,比如查询本周、上周或者上个月的数据。MySQL 提供了丰富的日期和时间函数,使得这类操作变得非常方便。...
查询上周的数据 SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now())-1; 查询当前月份的数据 select name,submittime from enterprise where date_fo
查询上个月的数据,可以结合date_format和DATE_SUB: ```sql SELECT name, submittime FROM enterprise WHERE date_format(submittime, '%Y-%m') = date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH), '%Y-%m');...
- **上个月**: ```sql SELECT name, submittime FROM enterprise WHERE DATE_FORMAT(submittime, '%Y-%m') = DATE_FORMAT(DATE_SUB(curdate(), INTERVAL 1 MONTH), '%Y-%m'); ``` 当使用这些时间日期函数进行...
本文将详细介绍如何使用PHP和MySQL查询特定时间段的数据,特别是针对当天、本周、本月和本年的记录,这些记录的时间戳字段存储在数据库中。 首先,我们来看如何查询当天的数据。PHP通过`date()`函数可以获取当前...
MySQL 中,您可以使用以下语句查询上周记录: ```sql SELECT * FROM ht_invoice_information WHERE create_date >= DATE_SUB(NOW(), INTERVAL 8 + WEEKDAY(NOW()) DAY) AND create_date (NOW(), INTERVAL 1 + ...
10. 查询上个月的数据: ```sql SELECT name, submittime FROM enterprise WHERE DATE_FORMAT(submittime, '%Y-%m') = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 MONTH), '%Y-%m'); ``` 这些SQL语句是基于...
7. **查询上周**: 判断时间字段所在的周是否为当前周减去1。例如: ```sql SELECT * FROM 表名 WHERE YEARWEEK(DATE_FORMAT(时间字段,'%Y-%m-%d')) = YEARWEEK(NOW()) - 1; ``` 8. **查询上月**: 使用`...
标题"本周和其他有用时间段SQL总计"暗示我们要探讨如何利用SQL来获取特定时间段内的数据总计,比如本周、本月、本年,以及过去的时间段,如上周、上个月和去年。以下是一些关于这个主题的关键知识点: 1. **日期和...
例如,使用`date('Y-m-d')`获取当前日期,`date('Y-m-d', strtotime('-1 day'))`获取昨日日期,`date('Y-m-d', strtotime('last monday'))`获取上周一日期,`date('Y-m-01')`获取本月第一天,`date('Y-m-d', ...