如果日期已过

时间:2019-04-05 14:20:17

标签: mysql sql

任何人都知道如何检查日期是否过去了。我的数据库中有一个返回日期列,它是一个将来的日期,当该日期过去时,我需要在触发器中包含此日期以提醒经理。我已经尝试过此代码,但无法正常工作。

DELIMITER //
CREATE TRIGGER date_expired BEFORE INSERT ON external_requests
FOR EACH ROW 
BEGIN 
IF return_date >= (return_date) Then 
SIGNAL SQLSTATE '45000' set message_text='This book has not been returned to the library';

END//
DELIMITER ;

1 个答案:

答案 0 :(得分:1)

您要寻找curdate()吗?

DELIMITER //
CREATE TRIGGER date_expired BEFORE INSERT ON external_requests
FOR EACH ROW 
BEGIN 
    IF return_date >= curdate() Then 
        SIGNAL SQLSTATE '45000' 
               set message_text='This book has not been returned to the library';
    end if;

END//
DELIMITER ;