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 相关文章推荐
用PHP编程语言开发动态WAP页面
Oct 09 PHP
php header Content-Type类型小结
Jul 03 PHP
PHP中获取文件扩展名的N种方法小结
Feb 27 PHP
PHP执行批量mysql语句的解决方法
May 02 PHP
php5.3 注意事项说明
Jul 01 PHP
php实现的ping端口函数实例
Nov 12 PHP
php指定长度分割字符串str_split函数用法示例
Jan 30 PHP
删除PHP数组中的重复元素的实现代码
Apr 10 PHP
php实现与python进行socket通信的方法示例
Aug 30 PHP
在云虚拟主机部署thinkphp5项目的步骤详解
Dec 21 PHP
PHP的介绍以及优势详细分析
Sep 05 PHP
Laravel 解决composer相关操作提示php相关异常的问题
Oct 23 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
星际玩家的三大定律
2020/03/04 星际争霸
一步一步学习PHP(5) 类和对象
2010/02/16 PHP
深入解析php之apc
2013/05/15 PHP
php+ajax无刷新上传图片实例代码
2015/11/17 PHP
PHP读取大文件的多种方法介绍
2016/04/04 PHP
ajax 缓存 问题 requestheader
2010/08/01 Javascript
JS上传前预览图片实例
2013/03/25 Javascript
js如何实现设计模式中的模板方法
2013/07/23 Javascript
js和jquery使按钮失效为不可用状态的方法
2014/01/26 Javascript
关于jQuery中的each方法(jQuery到底干了什么)
2014/03/05 Javascript
使用text方法获取Html元素文本信息示例
2014/09/01 Javascript
使用js dom和jquery分别实现简单增删改
2014/09/11 Javascript
node.js中使用socket.io的方法
2014/12/15 Javascript
举例讲解如何判断JavaScript中对象的类型
2016/04/22 Javascript
JS学习之表格的排序简单实例
2016/05/16 Javascript
BootStrap3中模态对话框的使用
2017/01/06 Javascript
在element-ui的el-tree组件中用render函数生成el-button的实例代码
2018/11/05 Javascript
详解react native页面间传递数据的几种方式
2018/11/07 Javascript
Vue中的this.$options.data()和this.$data用法说明
2020/07/26 Javascript
WebStorm无法正确识别Vue3组合式API的解决方案
2021/02/18 Vue.js
[04:40]2016国际邀请赛中国区预选赛全程TOP10镜头集锦
2016/07/01 DOTA
使用Python脚本将Bing的每日图片作为桌面的教程
2015/05/04 Python
django admin 后台实现三级联动的示例代码
2018/06/22 Python
浅谈python写入大量文件的问题
2018/11/09 Python
python监测当前联网状态并连接的实例
2018/12/18 Python
利用python实现.dcm格式图像转为.jpg格式
2020/01/13 Python
Sam’s Club山姆会员商店:沃尔玛旗下高端会员制商店
2017/01/16 全球购物
澳大利亚电子产品购物网站:Dick Smith
2017/02/02 全球购物
Stutterheim瑞典:瑞典高级外套时装品牌
2019/06/24 全球购物
自我鉴定的范文
2013/10/03 职场文书
活动策划邀请函
2014/02/06 职场文书
元宵节晚会主持人串词
2014/03/25 职场文书
2014年医院后勤工作总结
2014/12/06 职场文书
教师党员自我评价范文
2015/03/04 职场文书
湘江北去观后感
2015/06/15 职场文书
2016年小学生清明节广播稿
2015/12/17 职场文书