find if date is older than 30 days

Ella picture Ella · Aug 20, 2011 · Viewed 74k times · Source

The date string looks like this

2011-08-19 17:14:40

(year-month-day hours:minutes:seconds)

How can I find out if the date is older than the current date with more than 30 days?

Answer

RiaD picture RiaD · Aug 20, 2011

Try using something like this:

 if(strtotime('2011-08-19 17:14:40') < strtotime('-30 days')) {
     // this is true
 }

Besides, this string looks like it is stored in SQL as datetime/timestamp field. You can directly select all entries from your database with old dates using:

SELECT ... WHERE `datetime` + INTERVAL 30 DAY < NOW()