首页 > 编程知识 正文

mysql计算日期差

时间:2023-05-03 17:04:39 阅读:262389 作者:3424

工作中使用了阿里云的数据库,语法是用的postgresql,这个语言的时间函数计算跟impala和mysql等等都不太一样。业务中需要去做时间差的时候,本来想着用timediff()之类的函数去计算,但是postgresql并不支持,后来查了一下,发现postgresql的时间差的计算是用time+'x min’之类的解决:(工作代码)
case when update_time>create_time and update_time<create_time+‘12 hours’ then 1 else 0 end as twelve,
case when update_time>create_time+‘12 hours’ and update_time<create_time+‘24 hours’ then 1 else 0 end as twenty_four,
case when update_time>create_time+‘24 hours’ and update_time<create_time+‘48 hours’ then 1 else 0 end as forty_eight,
case when update_time>create_time+‘48 hours’ and update_time<create_time+‘72 hours’ then 1 else 0 end as seventy_two
参考:https://www.cnblogs.com/mchina/archive/2013/04/15/3010418.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。