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 相关文章推荐
超级实用的7个PHP代码片段分享
Jan 05 PHP
克隆一个新项目的快捷方式
Apr 10 PHP
用php制作简单分页(从数据库读取记录)的方法详解
May 04 PHP
用mysql_fetch_array()获取当前行数据的方法详解
Jun 05 PHP
php增删改查示例自己写的demo
Sep 04 PHP
php数据类型判断函数有哪些
Sep 23 PHP
Smarty模板学习笔记之Smarty简介
May 20 PHP
zen_cart实现支付前生成订单的方法
May 06 PHP
php版银联支付接口开发简明教程
Oct 14 PHP
Laravel中encrypt和decrypt的实现方法
Sep 24 PHP
php实现的AES加密类定义与用法示例
Jan 29 PHP
PHP大文件切割上传并带进度条功能示例
Jul 01 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强制更新图片缓存的方法
2015/02/11 PHP
Javascript UrlDecode函数代码
2010/01/09 Javascript
兼容IE和FF的js脚本代码小结(比较常用)
2010/12/06 Javascript
基于jquery的可多选的下拉列表框
2012/07/20 Javascript
Js实现网页键盘控制翻页的方法
2014/10/30 Javascript
jQuery的load()方法及其回调函数用法实例
2015/03/25 Javascript
ReactNative页面跳转实例代码
2016/09/27 Javascript
ES2015 Symbol 一种绝不重复的值
2016/12/25 Javascript
JS实现的简单下拉框联动功能示例
2018/05/11 Javascript
JavaScript轮播停留效果的实现思路
2018/05/24 Javascript
vue-cli 打包使用history模式的后端配置实例
2018/09/20 Javascript
基于vue和react的spa进行按需加载的实现方法
2018/09/29 Javascript
Vue中的基础过渡动画及实现原理解析
2018/12/04 Javascript
Typescript 中的 interface 和 type 到底有什么区别详解
2019/06/18 Javascript
jquery弹窗时禁止body滚动条滚动的例子
2019/09/21 jQuery
jQuery实现消息弹出框效果
2019/12/10 jQuery
Windows下PyMongo下载及安装教程
2015/04/27 Python
微信跳一跳游戏python脚本
2020/04/01 Python
python打印9宫格、25宫格等奇数格 满足横竖斜相加和相等
2019/07/19 Python
python实现简单银行管理系统
2019/10/25 Python
详解Python的爬虫框架 Scrapy
2020/08/03 Python
CSS3 flex布局之快速实现BorderLayout布局
2015/12/03 HTML / CSS
用CSS3的box-reflect设置文字倒影效果的方法讲解
2016/03/07 HTML / CSS
印度最好的在线药品订购网站:PharmEasy
2018/11/30 全球购物
德国珠宝和配件商店:Styleserver
2021/02/23 全球购物
什么是会话Bean
2015/05/14 面试题
Shell脚本如何向终端输出信息
2014/04/25 面试题
竞争上岗演讲稿
2014/01/05 职场文书
大学生涯自我鉴定
2014/01/16 职场文书
《谁的本领大》教后反思
2014/04/25 职场文书
高中教师先进事迹材料
2014/08/22 职场文书
健康状况证明书
2014/11/26 职场文书
2015年电厂工作总结范文
2015/05/13 职场文书
Python Pandas知识点之缺失值处理详解
2021/05/11 Python
如何用Python搭建gRPC服务
2021/06/30 Python
windows10声卡驱动怎么安装?win10声卡驱动安装操作步骤教程
2022/08/05 数码科技