I'm attempting to use PHP's date()
function to search my database for today's date, but the result is always for tomorrows date.
This code:
$date = date("Y-m-d");
is currently giving me 2018-08-02
, but it should be 2018-08-01
I've seen many questions on StackOverflow for this question:
- Date function in PHP gives always date one day behind
- php dates off by one day
- Adding one day to a date
- php date ("Y/m/d") is one day off
The solution is the same on all of them; use date_default_timezone_set()
, but I am already doing that in my index.php file.
date_default_timezone_set("US/Central");
I'm using a PHP framework, the index.php file is always loaded, no matter where I am in my application, and date_default_timezone_set()
is the 2nd line ran for my whole application.
How can I make date()
report the correct date?