Home >Backend Development >PHP Tutorial > 数据库里头存的格式是“2012-01-19”,怎样写sql比较日期小于几天的不显示呢

数据库里头存的格式是“2012-01-19”,怎样写sql比较日期小于几天的不显示呢

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 13:25:49979browse

数据库里面存的格式是“2012-01-19”,怎样写sql比较日期小于几天的不显示呢?
数据库里面存的格式是“2012-01-19”,怎样写sql比较日期小于几天的不显示呢? 


------解决方案--------------------
SELECT UNIX_TIMESTAMP('2012-01-19');
得到unix时间戳
------解决方案--------------------
SELECT * FROM `tablename` WHERE ADDTIME>DATE_SUB(CURRENT_TIMESTAMP(),INTERVAL 6 DAY)
------解决方案--------------------
select date_sub('2012-01-19', INTERVAL 2 DAY)
得到 2012-01-17
接下来的事情你应该会做了

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