How do I change MySQL timezone?


Posted in PHP onMarch 26, 2008

However, there are ways for you to get results that are in your preferred timezone. First determine how many 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 of 

SELECT NOW();

with

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

which will give you an EST date result. For a result in PST, you would 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.

PHP 相关文章推荐
c#中的实现php中的preg_replace
Dec 21 PHP
PHP CURL模拟登录新浪微博抓取页面内容 基于EaglePHP框架开发
Jan 16 PHP
如何使用PHP计算上一个月的今天
May 23 PHP
带密匙的php加密解密示例分享
Jan 29 PHP
ThinkPHP文件上传实例教程
Aug 22 PHP
PHP截取指定图片大小的方法
Dec 10 PHP
Smarty使用自定义资源的方法
Aug 08 PHP
PHP的Laravel框架结合MySQL与Redis数据库的使用部署
Mar 21 PHP
laravel学习教程之关联模型
Jul 30 PHP
PHP面向对象之工作单元(实例讲解)
Jun 26 PHP
thinkphp ajaxfileupload实现异步上传图片的示例
Aug 28 PHP
PHP ADODB生成下拉列表框功能示例
May 29 PHP
有关 PHP 和 MySQL 时区的一点总结
Mar 26 #PHP
使用 MySQL Date/Time 类型
Mar 26 #PHP
MySQL修改密码方法总结
Mar 25 #PHP
用phpmyadmin更改mysql5.0登录密码
Mar 25 #PHP
常用的php ADODB使用方法集锦
Mar 25 #PHP
PHP中ADODB类详解
Mar 25 #PHP
php下判断数组中是否存在相同的值array_unique
Mar 25 #PHP
You might like
php获得文件扩展名三法
2006/11/25 PHP
PHP开发中解决并发问题的几种实现方法分析
2017/11/13 PHP
JQuery 浮动导航栏实现代码
2009/08/27 Javascript
js获取鼠标点击的位置实现思路及代码
2014/05/09 Javascript
实现音乐播放器的代码(html5+css3+jquery)
2015/08/04 Javascript
JavaScript学习笔记之ES6数组方法
2016/03/25 Javascript
jQuery实现底部浮动窗口效果
2016/09/07 Javascript
js时间控件只显示年月
2017/01/08 Javascript
纯js的右下角弹窗实例
2017/03/12 Javascript
js实现自动图片轮播代码
2017/03/22 Javascript
thinkjs 文件上传功能实例代码
2017/11/08 Javascript
微信小程序实现美团菜单
2018/06/06 Javascript
解决layui富文本编辑器图片上传无法回显的问题
2019/09/18 Javascript
[01:21:07]EG vs Liquid 2018国际邀请赛淘汰赛BO3 第一场 8.25
2018/08/29 DOTA
python条件和循环的使用方法
2013/11/01 Python
Python代码的打包与发布详解
2014/07/30 Python
pygame学习笔记(5):游戏精灵
2015/04/15 Python
Python中的几种矩阵乘法(小结)
2019/07/10 Python
使用Python实现跳一跳自动跳跃功能
2019/07/10 Python
Python识别快递条形码及Tesseract-OCR使用详解
2019/07/15 Python
Django框架视图函数设计示例
2019/07/29 Python
django-rest-swagger对API接口注释的方法
2019/08/29 Python
简单的Python调度器Schedule详解
2019/08/30 Python
python实现飞机大战游戏(pygame版)
2020/10/26 Python
Python 自由定制表格的实现示例
2020/03/20 Python
Python字符串格式化f-string多种功能实现
2020/05/07 Python
详解matplotlib绘图样式(style)初探
2021/02/03 Python
HTML5引入的新数组TypedArray介绍
2012/12/24 HTML / CSS
Html5原生拖拽相关事件简介以及基础实现
2020/11/19 HTML / CSS
Vans(范斯)德国官网:美国南加州的原创极限运动潮牌
2017/05/02 全球购物
机械系大学毕业生推荐信
2013/11/27 职场文书
中级会计职业生涯规划书
2014/03/01 职场文书
2014五一国际劳动节活动总结范文
2014/04/14 职场文书
试用期旷工辞退通知书
2015/04/17 职场文书
电影小兵张嘎观后感
2015/06/03 职场文书
pytorch实现手写数字图片识别
2021/05/20 Python