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

krishna8723's avatar

What is the good way to store future datetime based on date, time & timezone offset.

Hello, I want to store future datetime based on user input date, time & timezone offset on server where timezone is UTC. Pls help. Thank You.

0 likes
8 replies
Sti3bas's avatar

@krishna8723 store user's timezone in users table, then pass it to Carbon: Carbon::parse($date)->timezone($user->timezone).

krishna8723's avatar

Actually i want to publish the post after specific date based on the user input where user can select particular date, time and timezone offset. User can view the post based on that selected timezone offset. @jlrdw @sti3bas

krishna8723's avatar

Yes. But i am having issue on setting up the proper datetime on database based on date, time & timezone offset. @jlrdw

jlrdw's avatar

As mentioned, you still store UTC time, but use the offset to get the users timezone.

Did you see the stackoverflow post.

Snapey's avatar
Snapey
Best Answer
Level 122

You only need to store what UTC time the post should be published.

So when they say what time to publish, convert it to UTC at that time and store the UTC value.

When, later, you show them what time it will be published, get the UTC time and apply their timezone.

Please or to participate in this conversation.