Hi everyone, wondering if I might be able to get some assistance on an issue I can't seem to figure out.
Basically, I have an application whereby a "Pitch Sheet" gets created and stored in the database. I'm using the built-in created_at column. Nothing particularly fancy, except that when these records get created the created_at timestamp is in UTC, per my config/app.php file's timezone setting.
I'm pretty sure that I want to keep the timezone as UTC, as this is will be global application.
The problem is that, for example, a "pitch sheet" was created yesterday (6/13) at 10:55pm EST. However, the created_at timestamp in the database is 6/14/2018 2:55am due to the timezone being UTC.
I have a "dashboard" that displays each pitch sheet by date, i.e.:
$date = Carbon::today();
$pitchsheets = PitchSheet::whereDate('created_at', $date)->get();
So the issue we're seeing is that when trying to pull up pitch sheets for today (6/14) it's including the sheet that was actually created yesterday since the timestamp is 6/14 2:55am UTC and $date being 6/14 EST.
So, one approach to fixing this might be to add another date field for the "applicable date", which would store "today's" date, then I could query based on that. But what I'm trying to figure out is whether or not there's a way to convert the created_at timestamp from the database to EST when using whereDate() and compare it to $date?
(eventually the timezone will need to be different by user, but for now I'm just wanting to hardcode it to EST)
I'm assuming I could use whereRaw and use some sort of casting/date conversion in the SQL query itself, but I'm hoping for a more native way to Laravel to accomplish this.
Any thoughts?
Thanks