MySQL 中正确的日期和时间列
我需要在表中更正时区不匹配。 unix 时间戳 1253568477 之前的所有日期和时间都需要在其值中添加 5 小时,以使其等于 GMT。
我有以下列...
date
(数据类型 date
),相差 -5 小时
time
(数据类型 time< /code>),关闭-5小时
timestamp
(数据类型int
),此列是正确的时间
时区关闭的原因是因为我的方式插入行时设置值...
$sql = "insert into email_opens (userid, email, serial, date, time, timestamp) values (
'$userid',
'$opened_by',
'$serial_number',
now(),
now()',
'".gmmktime()."'
)";
now()
值使用服务器时区(东部),而 gmmktime
值指定 GMT。此后我已更正此查询以始终使用 GMT。
有没有办法可以为那些时间戳 time
和 date
列添加 5 个小时1253568477 批量查询?
澄清:
我的目标是通过为每个值添加 5 小时,用正确的时间更新表中的每个不正确的行。
I have a timezone mismatch I need to correct in a table. All dates and times before unix timestamp 1253568477 need to have 5 hours added to their values to make them equal GMT.
I have the following columns...
date
(data type date
), off by -5 hours
time
(data type time
), off by -5 hours
timestamp
(data type int
), this column is the correct time
The reason the timezones are off is because of the way I was setting the values when inserting the rows...
$sql = "insert into email_opens (userid, email, serial, date, time, timestamp) values (
'$userid',
'$opened_by',
'$serial_number',
now(),
now()',
'".gmmktime()."'
)";
The now()
value was using the server timezone (eastern) whereas the gmmktime
value specified GMT. I have since corrected this query to always use GMT.
Is there a way I can add 5 hours to both time
and date
columns for those rows where timestamp < 1253568477 in one batch query?
Clarification:
My goal is to update each incorrect row in the table with the correct time by adding 5 hours to each value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
然后你可能需要这个:
所以,使用它:
Try with this:
And then you probably need this:
So, using that:
当然,计算出纠正问题的时间,这样您就知道只更新值小于时区更改的 unix 时间戳的记录。
然后更新字段并向这些记录添加 60 * 60 * 5(5 小时以秒为单位)。
因此,您的查询如下:
酷。
sure, work out the time you corrected the problem so you know only to update records that have a value less than the unix timestamp of your timezone change.
Then update the field and add 60 * 60 * 5 (5 hours in seconds) to those records.
So, your query would be the following:
Cool.