PHP/Mysql:日期比今天低 [英] PHP/Mysql: Date lower than today

查看:91
本文介绍了PHP/Mysql:日期比今天低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我有一个名为expires_in的字段,并且具有诸如2015-05-01(YYYY-MM-DD)之类的值,我需要对此字段进行搜索(从PHP)并返回

In my database I have a field that's named: expires_in and that has values such as 2015-05-01 (YYYY-MM-DD), I need to do a search on this field (from PHP) and get back

a)低于今天的日期(例如昨天或x天之前)
b)大于今天但距今天不到2周的日期

a) dates that are lower than today (eg yesterday or x days ago)
b) dates that are greater than today but less than 2 weeks from today

我有一种感觉,如果我知道a,那么b不会很难...

I have a feeling that if I know a then b won't be hard...

推荐答案

您应按以下方式查询MySQL数据库:

You should query the MySQL database as follows:

A)SELECT * FROM table WHERE expires_in < CURDATE()

B)SELECT * FROM table WHERE expires_in > CURDATE() AND expires_in < DATE_ADD(CURDATE(), INTERVAL 2 WEEK)

有关MySQL时间/日期函数的更多信息: https://dev.mysql.com/doc/refman/5.1/zh-CN/date-and-time-functions.html

More information about MySQL time/date functions: https://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

这篇关于PHP/Mysql:日期比今天低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆