Home  >  Article  >  Database  >  mysql 按照时间段来获取数据的方法_MySQL

mysql 按照时间段来获取数据的方法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:24:001200browse

bitsCN.com 时间格式为2013-03-12
查询出当天数据:

SELECT * FROM `table` WHERE date(时间字段) = curdate();

查询出当月字段:

SELECT *
FROM `table`
WHERE month( 时间字段) = month( now( ) ) ;

时间格式为1219876…… UNIX时间,只要应用“FROM_UNIXTIME( )”函数
例如查询当月:

SELECT *
FROM `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) ;

查询上一个月的呢?变通一下!

SELECT *
FROM `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) -1;
bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn