views:

36

answers:

4

I am using MySQL and PHP, and I want to find the difference between two dates.

I have a table named advertisers, which has a field web_start_date. I want to select all entries where the web_start_date is less than 30 days from the current date

+2  A: 

Just use the datediff MySQL function.

silent
+1 There's no need for adding or subtracting when there's a function designed for the job: `SELECT * FROM advertisers WHERE DATEDIFF(NOW(), web_start_date) < 30;`
Mike
...or swap the values round if you are comparing now with future dates: `SELECT * FROM advertisers WHERE DATEDIFF(web_start_date, NOW()) < 30;`
Mike
A: 

WHERE web_start_date < TIMESTAMPADD(DAY, 30, NOW())

Hammerite
A: 

hmmm.. try this, see if it work for you :)

SELECT * FROM advertisers WHERE DATE(web_start_date) > DATE_SUB(NOW(), INTERVAL 30 DAY)
Puaka
A: 

use DATEDIFF() function of mysql

Praveen kalal