0

I'm walking into a project where a database is already set up. Up until now, the client has been working with using NOW() in PHP to store a DateTime in mysql. The problem is that now they want people from all over the world to be able to return data and have it display in their current time. So I changed all the functions from NOW() to UTC_TIMESTAMP() so the database is using UTC for all stored DateTime stamps. Looking at the table it's stored as YYYY-MM-DD HH:MM:SS. So how can I can I convert, using PHP, that timestamp from a UTC time to what it would be in their timezone?

So if I'm in GMT-6, and there is a timestamp of "2015-12-08 15:17:20" it'll display as "2015-12-08 09:17:20" on the page?

I've been looking at all sorts of PHP options, I can't really change anything in SQL, nor the database structure, all I can do is take the data being stored and manipulate it with PHP.

Flynn
  • 193
  • 2
  • 5
  • 18
  • And yes, I do know that this can be done very easily just using epoch time stamps, but the problem is that I'm trying to fix this without having to get someone on their end that can figure out how to change their time column from DateTime to INT(10) – Flynn Dec 08 '15 at 15:21
  • Are your `DATETIME` values all stored in UTC or some other single time zone? – O. Jones Dec 09 '15 at 03:52
  • how about: "Convert UTC dates to local time in PHP" http://stackoverflow.com/questions/3792066/convert-utc-dates-to-local-time-in-php – snitch182 Mar 10 '17 at 10:50

0 Answers0