MySQL 中正确的日期和时间列

发布于 2024-08-04 22:42:38 字数 753 浏览 7 评论 0原文

我需要在表中更正时区不匹配。 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。

有没有办法可以为那些时间戳 timedate 列添加 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守望孤独 2024-08-11 22:42:38

试试这个:

UPDATE mail_opens SET date = DATE_ADD(CONCAT(date, ' ', time), INTERVAL 5 HOUR), time = DATE_ADD(CONCAT(date, ' ', time), INTERVAL 5 HOUR);

然后你可能需要这个:

<?php
    echo date('Y-m-d H:i:s')."<br>";
    $addhours = strtotime('+5 hour');
    echo $addhours."<br>";
    $newdate = date('Y-m-d H:i:s', $addhours);
    echo $newdate;
?>

所以,使用它:

<?php
$addhours = strtotime('+5 hour');
$newdate = date('Y-m-d H:i:s', $addhours);
$sql = "insert into email_opens (userid, email, serial, date, time, timestamp) values (
'$userid',
'$opened_by',
'$serial_number',
'$newdate',
'$newdate',
'".gmmktime()."'
)";
?>

Try with this:

UPDATE mail_opens SET date = DATE_ADD(CONCAT(date, ' ', time), INTERVAL 5 HOUR), time = DATE_ADD(CONCAT(date, ' ', time), INTERVAL 5 HOUR);

And then you probably need this:

<?php
    echo date('Y-m-d H:i:s')."<br>";
    $addhours = strtotime('+5 hour');
    echo $addhours."<br>";
    $newdate = date('Y-m-d H:i:s', $addhours);
    echo $newdate;
?>

So, using that:

<?php
$addhours = strtotime('+5 hour');
$newdate = date('Y-m-d H:i:s', $addhours);
$sql = "insert into email_opens (userid, email, serial, date, time, timestamp) values (
'$userid',
'$opened_by',
'$serial_number',
'$newdate',
'$newdate',
'".gmmktime()."'
)";
?>
王权女流氓 2024-08-11 22:42:38

当然,计算出纠正问题的时间,这样您就知道只更新值小于时区更改的 unix 时间戳的记录。

然后更新字段并向这些记录添加 60 * 60 * 5(5 小时以秒为单位)。

因此,您的查询如下:

UPDATE email_opens SET timestamp = (timestamp + 18000) WHERE timestamp < 1253568477;

酷。

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:

UPDATE email_opens SET timestamp = (timestamp + 18000) WHERE timestamp < 1253568477;

Cool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文