compare the "correct" time
Of "correct" depends of you want
-
setTimezone changes the hour
-
shiftTimezone does not change it
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Working on a application that has dates and times on different timezones. I need to compare the "projected_arrival" to the "time_window_close". The time_window_close is on EST and the projected arrival on GMT. Not matter what i'm doing keeps giving me the same result. Applying ->setTimezome() does show the projected arrival on the correct time so it has to be a way to compare the "correct" time with the window.
Psy Shell v0.11.2 (PHP 8.0.10 — cli) by Justin Hileman
>>> $s=Stop::find(673195)
[!] Aliasing 'Stop' to 'App\Models\Stop' for this Tinker session.
=> App\Models\Stop {#4076
id: 673195,
round_id: 91546,
planned_sequence: 12,
planned_arrival: "2022-03-24 16:28:09",
projected_arrival: "2022-03-24 16:28:09",
location_id: 26050,
size1: 37.77,
time_window_open: "2022-03-24 10:00:00",
time_window_close: "2022-03-24 14:00:00",
projected_time_window_missed: -148,
stop_reason_id: 1,
show: "1",
created_at: "2022-03-24 17:25:07",
updated_at: "2022-03-24 17:25:07",
}
>>> $s->projected_arrival->diffInMinutes($s->time_window_close,false)
=> -148
>>> $s->projected_arrival->setTimezone('America/New_York')->diffInMinutes($s->time_window_close,false)
=> -148
>>> $s->projected_arrival->setTimezone('America/New_York')
=> Illuminate\Support\Carbon @1648139289 {#4692
date: 2022-03-24 12:28:09.0 America/New_York (-04:00),
}
Please or to participate in this conversation.