MySQL - PHP user local time

Hi Experts,

I know this question has been asked alot of time before, but I am not able to achieve this task. I have different transaction date and times stored in the database (Type: timestamp) according to UTC timezone.

I have users from different countries visiting the website and I want to display the transaction time according to user's timezone. What is the best way to achieve it? Should I store the user's timezone in the database? or is there anyway to detect the user's timezone and convert it while echoing the date and time.

Thanks in Advance.
Rahul SehrawatAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is a rendering issue, part of the data you need to get from the client is their local time zone by either asking and storing it in a cookie, or using IP based determination or getting the data from the HTTP header request if indicated there.

If you use the determination, you could use the data in the cookie to set TZ in the PHP when dealing with responding to individual requests.
Ray PaseurCommented:
It is a common question, and one we've got good answers for.  Short answer:  Store your database information in UTC timezone.  Ask the client to choose their preferred timezone, or detect client time using JavaScript; you can store this in the database and it may be safer in the database than using a cookie,, because the client can erase the cookie.  Convert the date/time information for display according to the client time zone.  There is guidance with examples in the Practical Application parts of these articles.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.