Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL current_timestamp+14

Hi I am having problem creating a table.
Here’s what I am trying to do:
I have a table that automatically inserts current time and a current time + 14 days.

Below is my code:

'''
create table borrowedbook (
studentEmail varchar(255) not null,
bookId varchar(255) not null,
borrowedDate datetime NOT NULL DEFAULT  current_timestamp(),
returnedDate datetime,
dueDate datetime NOT null default current_timestamp()+14,

FOREIGN KEY (studentEmail) REFERENCES student(studentEmail),
FOREIGN KEY (bookId) REFERENCES book(bookId)
);
'''

I need to make dueDate field work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

need help!

edit: I am using DBeaver, mysql

>Solution :

You can use date_add(time_stamp, interval):

create table borrowedbook (
studentEmail varchar(255) not null,
bookId varchar(255) not null,
borrowedDate datetime NOT NULL DEFAULT  current_timestamp(),
returnedDate datetime,

dueDate datetime NOT null default DATE_ADD(current_timestamp, INTERVAL 14 DAY),

FOREIGN KEY (studentEmail) REFERENCES student(studentEmail),
FOREIGN KEY (bookId) REFERENCES book(bookId)
);

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading