views:

58

answers:

2

Hello guys, I have datetime-row in mysql database. I have to check time between now and that date using php. If the range is bigger then 1 month - do somtething.

I tried something like this:

$dateFromMysql = strtotime($rowData);
$currentDate = date("m/d/y g:i A");

And then comparsion by hands. It's ugly.

+2  A: 
SELECT  *
FROM    mytable
WHERE   mydatetime <= NOW() - INTERVAL 1 MONTH
        OR mydatetime >= NOW() + INTERVAL 1 MONTH

This query returns all dates that are at least 1 month apart from NOW() (either in the past or in the future).

Quassnoi
Thanks, this works great.
Ockonal
+1  A: 
$timeFromMysql = strtotime($rowData);
$currentTime = time();

if (abs($timeFromMysql - $currenTime) > 30*24*60*60) {
  // DO!
}
Joel L