N
N
Nikita Kravchenko2019-06-04 20:25:16
Laravel
Nikita Kravchenko, 2019-06-04 20:25:16

How to group materials based on q/w?

Hello!
There is a task to group materials by date (date of event). In the database as timestamp in utc.
Here's what happened:
5cf6a8cc6a6f7026771261.jpeg
But you need to take into account the user's time zone. Therefore, the date will change a little and on some days the news will shift and turn out to be on other days.)
Here's what I got, but I just can't add the user's timezone to all this:

return Match::select('id', 'date')
            ->orderBy('date', 'asc')
            ->get()
            ->groupBy(function($val) {return Carbon::parse($val->date)->format('m-d');});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Immortal_pony, 2019-06-04
@nkdev55

Do you have a field like mysql timestamp or int(11) in the database?
In both cases, something like this:
where +10:00 is the user's time zone.
If your unix_timestamp is in int (11), then before CONVERT_TZ you need to do another FROM_UNIXTIME

A
Alex Wells, 2019-06-04
@Alex_Wells

The backend does not know about the user's time zone. From the word "absolutely". UTC comes to him, he gives UTC. If you want an offset, do the grouping at the front (where it should be, by the way).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question