Hello guys. So i'm trying to set correct time-zone on Carbon::today() for getting all of the results created for this day.
Let's explain a little bit more.
I have a command that archive the Notes when created_at column is today, so I get all Notes that are created today and check them in foreach based on Building model timezone
Database structure:
Buildings:
-id
-name
-timezone
Notes:
-id
-name
-created_at
-updated_at
-building_id (reference id on buildings)
My code:
$notes = Note::where('archived', null)
->whereDate('created_at',Carbon::today())
->get();
foreach($notes as $note) {
// Set the current timezone
date_default_timezone_set($note->building->timezone)
$note->update([
'archived' =>1,
'archived_at'=>Carbon::now()
]) // update archive status etc...
}
I want Carbon::today() to be with the current timezone of the record building.
I've tried with that query too:
select
*
from
`notes`
inner join `buildings` on `notes`.`building_id` = `buildings`.`id`
where
date(`notes`.`created_at`) = CONVERT_TZ('NOW()', 'UTC', `building`.`timezone`);
Is there any way to do that? Thanks. :)