How I resolved a PHP error when checking today vs tomorrow

Steve Sohcot
Oct 16, 2020

--

I was using PHP’s date_diff() function to compare 2 dates. I wanted to make sure that a date that the user selected was at least one day away from today.

The issue was that for “today” I was using:

define("TODAYSDATE", gmdate("Y-m-d G:i:s", time()) );

And comparing this against the user inputted date.

When I compared “today” vs “tomorrow,” it said that there were 0 days. I was expecting to see 1 day.

The issue was, that I was (falsely) including the time. The solution was to change it to this:

gmdate('Y-m-d', time());

--

--

No responses yet