Search code examples
phpdatetimecomparisontimezone

Comparing dates via > and < operators


All across my php code i'm storing dates and times in UTC, but i'm also using mysql to store datetimes (also in utc).

is there any way that date comparisons can fail with the greater than and less than operator?

        $curdate=date('Y-m-d H:i:s');
        if($start_datetime>$curdate)

Solution

  • Nope.
    There is no way for them to fail.
    Mysql date format is intentionally made for this purpose.

    There is not a single reason to convert it in whatever else format to compare.