Hi, I was wondering how to verify if a date from a column is smaller than another date from another column.
Bascially, we'll say it's a promotion that goes on from 02-01-2012('promotion_start' column) until 03-01-2012('promotion_end' column). That is good but, what if the ending date is, 01-01-2012('promotion_end' column)?
If it's not good I would like to raise and error/exception.
I tried making a trigger but it's been a while and I could not get it to work. (Kinda rusty on triggers and I couldnt find any decent exemple about dates).
Here it is:
CREATE TRIGGER `test` BEFORE INSERT ON `promotion`
FOR EACH ROW BEGIN BEGIN IF NEW.DATE_FIN_PROMOTION < NEW.DATE_DEBUT_PROMOTION
THEN call exception('Promotion cannot end before start.); END IF; END; END;
I'm not sure where I should post this but I figured here is a good place since I use InnoDB. Also, if it matters I use HeidiSQL.
Thanks
Bascially, we'll say it's a promotion that goes on from 02-01-2012('promotion_start' column) until 03-01-2012('promotion_end' column). That is good but, what if the ending date is, 01-01-2012('promotion_end' column)?
If it's not good I would like to raise and error/exception.
I tried making a trigger but it's been a while and I could not get it to work. (Kinda rusty on triggers and I couldnt find any decent exemple about dates).
Here it is:
CREATE TRIGGER `test` BEFORE INSERT ON `promotion`
FOR EACH ROW BEGIN BEGIN IF NEW.DATE_FIN_PROMOTION < NEW.DATE_DEBUT_PROMOTION
THEN call exception('Promotion cannot end before start.); END IF; END; END;
I'm not sure where I should post this but I figured here is a good place since I use InnoDB. Also, if it matters I use HeidiSQL.
Thanks