Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thebigk's avatar
Level 13

Carbon - Modify Date Based on Timezone

My goal is to get the timestamp stored in database and show it in human readable format to the user based on their 'timezone'.

This looked easy; and here's why I have -

$messages->first()->created_at->setTimezone($user_timezone)->format('d M y, h:m a')

So if the message was received at 5:00PM in India, it should be some other time shown to the user viewing it from Europe or USA. However, this is not working as expected. I'm getting the same date for every user; irrespective of the timezone.

The date set in database is UTC. What am I doing wrong?

0 likes
3 replies
JohnBraun's avatar

What does this give you?

dd($messages->first()->created_at->setTimezone($user_timezone)->tzName);
thebigk's avatar
Level 13

@johnbraun - just fixed the bug. It was this format: d M y, g:i A ; that works as expected. Nothing wrong with timezones.

Please or to participate in this conversation.