How do I change MySQL timezone?

Source: Internet
Author: User
Tags mysql manual

However, there are ways for you to get results that are in your preferred timezone. first determine how does hours your desired timezone is off from MST. for example, est is + 2 hours. PST is-1 hour.

Knowing the Time Offset, you can replace all your SQL statements

Select now ();

With

Select date_add (now (), interval 2 hour );

Which will give you an EST date result. For a result in PST, you wowould do:

Select date_sub (now (), interval 1 hour );

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

Select unix_timestamp () ++ (3600*2 );

Select from_unixtime (unix_timestamp () + (3600*2 ));

See the MySQL Manual's date and time functions for more information.

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

1. Find every place in your code where a date or time is displayed to the 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 code where dates or times are input into your system and have a user defined function add or subtract the appropriate number of hours before storing it.

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.