How to change timezone for MySQL on a cPanel server:

For many of the websites there will be different time elements used for displaying time. It will use the server time this, but in some cases we need to have different time for the website and it is not possible to change the server time.

So in that case we can change the MySQL timezone to keep the website updated with the required timezone. For that first you need to know the function that will display the timezone for MySQL, it is the “MySQL NOW()” function that display the timezone. To check the current time using MySQL, you need to enter into the command line and call the “MySQL NOW()” function.

For Example;

root@iserver2 [~]# mysql -e "SELECT NOW()";
+---------------------+
| NOW() |
+---------------------+
| 2015-03-23 01:17:24 |
+---------------------+
root@iserver2 [~]# date
Mon Mar 23 01:17:31 EDT 2015

The command,

mysql -e "SELECT NOW()";

will show the date and time set to mysql function.

So by modifying this function, you can set different time to your website. For that see the following examples to add various modifications to the function.

For increment 4 hours to the value of  “SELECT NOW()” function you can use syntax as follows,

SELECT DATE_ADD(NOW(), INTERVAL 4 HOUR);

And for decrease 4 hours from the current value, you need to use the syntax as follows,

SELECT DATE_SUB(NOW(), INTERVAL 4 HOUR);

That’s it

If you need our help to fix any issues on your server. Please feel free to contact us, simply email to support@iserversupport.com

Monthly server support with Unlimited tickets, 24×7 monitoring, Security Audit and lot more for just $59