Fix your github and twitter links on Laracasts profile.
Where Date Filter in Auth User Time zone
Hi, my default laravel application timezone is America/Los_Angeles (pst) , I'm storing all the timestamps like created at with this timezone.
In the user profile, we are providing options to select a timezone. while showing the list of data for example in trip listing I'm showing created at as per user selected time zone ( $date->setTimezone($user->timezone);)
For example, if the trip Id 197 has created_at 2020-10-06 23:00:00 stored in db (as per default application timezone i.e pst) while in the listing I'm showing 2020-11-06 02:00:00 (est timezone as per user profile).
Now everything works fine until I had to add end date filter in the listing.
The problem is if I'm selecting 2020-11-06 in the date filter, in result it is still getting 197 trip id because in the database it is stored as 2020-10-06 23:00:00.
My db quert is $brokers->whereDate('created_at', '>=' ,$request->end_date); . I have only date and not time in request for filter trips
I need to somehow pass timezone in this query or is there any better solution for this.
Slight tweaks, key part being to add the start of day time before converting into the application timezone.
$date = Carbon::parse($request->end_date, $user->timezone)
->startOfDay()
->setTimezone(config('app.timezone'));
$brokers->where('created_at', '>=', $date);
Please or to participate in this conversation.