Comparing dates and dates

I have datetime-row in mysql database. I need to check the time between this date and the date using php. If the range is more than 1 month, do something.

I've tried something like this:

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

      

And then contemplation with hands. It's ugly.

+2


a source to share


2 answers


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 in length from NOW()

(either in the past or in the future).

+2


a source


$timeFromMysql = strtotime($rowData);
$currentTime = time();

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

      



+1


a source







All Articles