Using dates from a query in an IF statement

I know how to only return a row with a date older than 30 days in a mySQL query, but I’m uncertain how to do it in PHP. How do I write an IF statement that is similar to this following?

$dateFromDB = ‘2011-09-01 04:42:24’

if ($dateFromDB > 30 days) {

//execute additional code here


if((time() - strtotime($dateFromDB)) > (30*24*60*60)){

Get the current timestamp in seconds and subtract the stored timestamp (converted to a timestamp in seconds). If that is greater than 30 days (in seconds), then do stuff.

Just make sure the timezone of the current time and the stored time are the same.

That’s the same code. It just doesn’t have all the logic in a single line. It might be easier to understand this way if my example code didn’t make sense.

If you want to make the operations in php, see this example:

$dateFromDB = '2011-09-01 04:42:24';
$timestamp_date = strtotime($dateFromDB);
$time_diff = time() - $timestamp_date;
$days30 = 30*24*60*60;

echo $time_diff;       // for debug, 30 days is 2592000 seconds

if ($time_diff > $days30) {
  //execute additional code here