0

I am trying to create a table in MySQL(current version) that fills in the current date and the return date 7 days later.

I have the code set up like this:

CREATE TABLE Loans (
loan_id int(5) not null auto_increment primary key,
loan_date CURDATE,
return_date CURDATE (getdate()+7),
loan_notes varchar(200)
);

Obviously, this is not working. I have tried it with DATE, DATETIME (basically any variation on DATE) and the MySQL helpguide is... not so helpful here. I tried checking a few other answers on here but haven't had any luck. I could set a form linked to MySQL that asks for the user to input the info, but I would rather have it auto-generate if I can.

Any suggestions?

SassyG
  • 41
  • 5
  • `CREATE TABLE Loans (loan_id int(5) not null auto_increment primary key, createdAt DATETIME DEFAULT CURRENT_TIMESTAMP, loan_date DATE AS (DATE(createdAt)), return_date DATE AS (DATE(createdAt) + INTERVAL 7 DAY), loan_notes varchar(200) );` – Akina Nov 24 '20 at 07:29
  • Thank you for the help! My first database with MySQL... – SassyG Nov 29 '20 at 00:45

0 Answers0