MySQL比较时间(datetime)大小

遇到一个业务功能需要将当前时间与数据库中的会议开始、结束时间进行比较,记录一下,方便下次用。

用unix_timestamp函数,将字符型的时间,转成unix时间戳。

select meeting_id,meeting_name,start_time,end_time from meeting_data 
    where meeting_id REGEXP '[0-9]{4}0001' 
        and unix_timestamp(start_time) < unix_timestamp(NOW()) 
        and unix_timestamp(end_time) > unix_timestamp(NOW());

猜你喜欢

转载自blog.csdn.net/qq_27124771/article/details/81219550