1

I'm trying to create a trigger which returns the current date. But I'm struggling to include Curdate() function in a string

 DELIMITER $$ 
create trigger invalid_date 
    before insert on invoice 
    for each row 
begin 
    if new.date_in <> CURDATE() then 
        signal sqlstate '45000' set message_text = 
            "TriggerError: The date_in date should be Curdate()" ;
        end if ;
end$$ 
DELIMITER;

Doing it this way won't return the current date but rather just treat Curdate() as a string. My question is how do I include the Curdate() into the error message and actually return a date.

1
  • Have you tried CONCAT? Commented Oct 25, 2021 at 16:36

1 Answer 1

1

You can use CONCAT function to print date.

message_text = CONCAT("Your string: ", CURDATE())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.