MySQL时间函数-获取当前时间-时间差

时间:2023-11-19 17:55:08

MySQL中获取当前时间为now(),不同于sqlserver getdate()。

SQLServer转MySQL除变化top 1 -> limit 1之后报错:

select  1 from record_visitor where visitor_ip='' and datediff(mi,visitor_time,getdate())<=30 limit 1

[Err] 1582 - Incorrect parameter count in the call to native function 'datediff'

搜索了是MySQL->DATEDIFF只计算到天的单位。

正确写法:

select  1 from record_visitor where visitor_ip='' and TIMESTAMPDIFF(MINUTE,visitor_time,now())<=30 limit 1