Mysql Truncated incorrect time value

Mysql Truncated incorrect time value

发现一个mysql的问题,当我们做数据定时更新操作的时候,比如说定时作废48小时内未付款的订单的时候,如果用到mysql TIMEDIFF(var1,var2)函数

例如:UPDATE justice_user_customer SET STATUS=0 WHERE TIMEDIFF(SYSDATE(),update_time)>='48:00:00'

这个sql一开始没有问题,完全正常,但是某一天会突然报错,会出现Truncated incorrect time value: '1000:59:44' 这样奇怪的错误,根本原因是这个函数是算两个日期的时间差,但是他的取值最大只到838:59:59(不到35天)


所以会出现这样一个现象,一开始执行成功的sql,到了某一天不知不觉的报错了!

为了防止出现这样的错误,改用如下sql

 

UPDATE justice_user_customer SET STATUS=0 WHERE UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(update_time)>172800(2天)

 

--摘录官方文档函数的解释

 

timediff(expr1,expr2)

timediff() returns expr1 – expr2 expressed as a time value. expr1 and expr2 are time or date-and-time expressions, but both must be of the same type. 

 

unix_timestamp(), unix_timestamp(date)

if called with no argument, returns a unix timestamp (seconds since '1970-01-01 00:00:00' utc) as an unsigned integer. if unix_timestamp() is called with a date argument, it returns the value of the argument as seconds since '1970-01-01 00:00:00' utc. date may be a date string, a datetime string, a timestamp, or a number in the format yymmdd or yyyymmdd. the server interprets date as a value in the current time zone and converts it to an internal value in utc. clients can set their time zone as described in section 10.6, “Mysql server time zone support”.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值