查询当天的记录
select * from hb_article_view where TO_DAYS(hb_AddTime) = TO_DAYS(NOW())
查询当前这周的数据
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 * 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(时间字段名)
近30天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名)
本月
SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
上一月
SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( 时间字段名, '%Y%m' ) ) =1
#查询本季度数据
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(now());
#查询上季度数据
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));
#查询本年数据
select * from `ht_invoice_information` where YEAR(create_date)=YEAR(NOW());
#查询上年数据
select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));
查询当前这周的数据
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 下月第一天
where date(regdate) = curdate();
select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now())
SELECT date( c_instime ) ,curdate( )
FROM `t_score`
WHERE 1
LIMIT 0 , 30
分享到:
相关推荐
查询上个月的数据同样可以通过比较月份的方式来实现,只需要将当前时间减去一个月的时间差: ```sql SELECT name, submittime FROM enterprise WHERE date_format(submittime, '%Y-%m') = date_format(DATE_SUB...
### MySQL查询本周、上周与上个月份的相关知识点 在日常工作中,我们经常需要根据不同的时间范围来筛选数据,比如查询本周、上周或者上个月的数据。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
本文将详细介绍如何使用PHP和MySQL查询特定时间段的数据,特别是针对当天、本周、本月和本年的记录,这些记录的时间戳字段存储在数据库中。 首先,我们来看如何查询当天的数据。PHP通过`date()`函数可以获取当前...
- **上个月**: ```sql SELECT name, submittime FROM enterprise WHERE DATE_FORMAT(submittime, '%Y-%m') = DATE_FORMAT(DATE_SUB(curdate(), INTERVAL 1 MONTH), '%Y-%m'); ``` 当使用这些时间日期函数进行...
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', ...