0

I currently use $curdate=date('Y-m-d H:i:s'); to enter a timestamp to my blog's MySQL.

The problem is that the timezone of my MySQL is 2 hours ahead. At least in the timesaving period (I don't know if it is going to be any different when the timesaving period is over).

How should I redefine $curdate so that it records correct time based on PST time?

2
  • 1
    You might try date_default_timezone_set('America/Los_Angeles') in your script prior to the date() function. Commented Dec 15, 2011 at 13:17
  • thanks for the correct timezone example, too... Commented Dec 15, 2011 at 13:32

1 Answer 1

2

You can set the timezone the PHP uses for the duration of the execution of your script with date_default_timezone_set().

If you need to do something in your own timezone later in the execution of you script, you can call it again to set it back.

Alternatively (better?), if you use the MySQL NOW() function in your query, the time entered into the database will be calculated by MySQL, according to it's own timezone.

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

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.