How does I change MySQL timezone?_php Tips

Source: Internet
Author: User
Tags mysql manual


However, there are ways for your to get results this are in your preferred. The determine how many hours your desired timezone are off from MST. For example, EST is +2 hours. PST is-1 Hour.

Knowing the time offset, your can replace all your SQL statements of


SELECT now ();

With


SELECT Date_add (now (), INTERVAL 2 HOUR);

Which'll give you a EST date result. For a result in PST, your would do:


SELECT Date_sub (now (), INTERVAL 1 HOUR);

If you are are working with time in seconds instead of dates, then factor in the offset in seconds. Because there are 3600 seconds in a hour, and EST are 2 hours later than MST, the following converts timestamps from MST t o EST:


SELECT Unix_timestamp () + (3600 * 2);

SELECT From_unixtime (Unix_timestamp () + (3600 * 2));

"The MySQL Manual ' s Date and time functions for more information."

Depending on your application, your may also need to does one of the following (but not both):

1. Find every place in your code where a date or the "displayed to" browser and have a user defined function change It to add or subtract the appropriate number of hours before displaying it.

2. Find every place in your the code where dates or times are input into your system and have a user defined function add or s Ubtract the appropriate number of hours before storing it.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.