Home > php教程 > php手册 > body text

MySql 按时间段查询数据方法(实例说明)

WBOY
Release: 2016-06-13 12:26:19
Original
1487 people have browsed it

时间格式为2008-06-16
查询出当天数据:
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;
就这么简单,复杂的以后再补充!

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template