Compare DATETIME column date with current date in PHP?

php

Solution

Why not have SQL do the comparison for you?

SELECT *, DATE(`Date`) < DATE(NOW()) AS is_old ...

Then you've got a column called 'is_old' which is 1 if the date is before today and 0 if it's not. So, in PHP, all you need to do is something like:

if ($row['is_old']) {
    // handle the old date case
} 

Problem

I have a DATETIME column that stores values such as: 2012-05-20 14:00:00 How do I compare the date in `$row['Date']` with current date (time is not important) to see if it's older than today? ``` if($row['Date'] < ...) { echo 'date has passed' } ```

Original source