0

Im using php to set the current timezone for a site:

date_default_timezone_set('America/New_York');

How could I, at the same time, set the same time zone for mysql so that when I use NOW() it uses the timezone set in php?

2
  • You could do so in php.ini directly instead, if you need so. Commented Aug 25, 2012 at 17:54
  • @Lion This is for multiple sites, so I need to load it on a per site basis. Commented Aug 25, 2012 at 17:55

2 Answers 2

3

Don't.

The best practice is to store UTC in the database.

Sign up to request clarification or add additional context in comments.

3 Comments

The sites are geo based, so I need to be accurate with time for rows in the database.
@John that doesn't change the fact that you should store the datetimes as UTC in the database. Always. You convert them to the relevant locale when they're retrieved. Any other method is just asking for trouble.
@rdlowrey So set the timezone for mysql to UTC and use NOW() and then convert to the proper timezone for whatever timezone the site is currently in?
1

You can change your Mysql timezone using SET time_zone = timezone;

http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.