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

WBOY
Release: 2016-05-17 09:34:29
Original
972 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;
就这么简单,复杂的以后再补充!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!