I have a table with date which is entered when the member joins the club. The column is bog standard with DATE as type. No need to have time.
Basically I am trying to find a way that it can not be in the future?
You can use triggers. Below is a fully-functional tested example:
create table t(signup_date date not null);
delimiter //
create trigger ins_check_date before insert on t
for each row
begin
if (new.signup_date > current_date()) then
signal sqlstate '45000' set message_text = 'Date cannot be in the future';
end if;
end//
create trigger up_check_date before update on t
for each row
begin
if (new.signup_date > current_date()) then
signal sqlstate '45000' set message_text = 'Date cannot be in the future';
end if;
end//
delimiter ;
insert into t values (current_date());
insert into t values (current_date() - interval 1 day);
insert into t values (current_date() - interval 2 day);
insert into t values (current_date() + interval 1 day);
select * from t;
update t set signup_date = signup_date - interval 1 month
where signup_date = current_date() - interval 1 day;
update t set signup_date = signup_date + interval 1 month
where signup_date = current_date();
select * from t;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.