Ryan
Ryan

Reputation: 10049

PHP/Mysql: Date lower than today

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) 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

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

Upvotes: 2

Views: 11784

Answers (1)

upful
upful

Reputation: 960

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)

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

Upvotes: 11

Related Questions