【问题标题】:How to update a timestamp field of a mysql table ?如何更新 mysql 表的时间戳字段?
【发布时间】:2011-12-26 10:48:17
【问题描述】:

我想将所有空的 logout_time 字段更新为 2011-12-26 14:48:36。

我尝试了以下查询以更新 log_details 表中的 logout_time 字段(时间戳):

update log_details set logout_time='2011-12-26 14:48:36',tab_status='0' 
where logout_time =''

它不起作用。请帮我解决它。

【问题讨论】:

  • 您尝试运行此命令时遇到的确切错误是什么?你把 ;最后(我问是因为它不在您在此处键入的查询中,并且总是会破坏事情)
  • log_details 是表名,logout_time 是表中的时间戳字段,存储用户的注销时间。由于一些错误,值没有按我的预期添加,所以我必须手动将时间戳值更改为 2011-12-26 14:48:36,无论它为空。

标签: mysql timestamp field


【解决方案1】:
update log_details set logout_time='2011-12-26 14:48:36',tab_status='0' 
where logout_time IS NULL

【讨论】:

    【解决方案2】:

    以这种方式尝试UNIX_TIMESTAMP函数:

    update log_details set logout_time=UNIX_TIMESTAMP('2011-12-26 14:48:36'),tab_status='0' 
    where logout_time =''
    

    【讨论】:

      【解决方案3】:
      update log_details set logout_time='2011-12-26 14:48:36',tab_status='0' 
      
      where logout_time ='0000-00-00 00:00:00'
      

      这个查询应该会有所帮助,因为时间戳列为空意味着“0000-00-00 00:00:00”

      【讨论】:

        【解决方案4】:

        检查那些“空”字段是否为“0000-00-00 00:00:00”。如果它的时间戳很可能是这种情况,而不是“空”为空。最好的方法是检查您想要更新的字段中的确切内容。

        //更新

        如果字段实际上是NULL,那么它应该是

        update log_details set logout_time='2011-12-26 14:48:36',tab_status='0' 
        where logout_time IS NULL
        

        【讨论】:

        • 时间戳字段实际上是空的。我想使用查询用手动值填充该字段。请告诉我我该怎么做?我有什么办法吗?
        猜你喜欢
        • 2012-11-14
        • 2015-08-01
        • 2021-04-19
        • 1970-01-01
        • 2012-05-27
        • 1970-01-01
        • 2013-05-10
        • 2015-11-19
        • 1970-01-01
        相关资源
        最近更新 更多