If a date has passed

Asked by At

Anyone know how to check if a date has gone by. I have a return date column in my database which is a future date and when this date has gone by I need to include this inside a trigger to alert the manager. I have tried this code but it is not working.

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 Answers

1
Gordon Linoff On

Are you looking for 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 ;