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

make default value for a field to be current_timestamp + some interval

i wanna make the default value of a field to be 30 days more than whatever the current timestamp is i tried a lot of stuff with dateadd() and addtime() but it always gave me an syntax error

create table test (Id serial,name varchar(10),Date timestamp default dateadd(day,30,cuurent_timestamp));

this might give a rough idea of what i’m trying to achieve.

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

>Solution :

dateadd is an SQL server function; mysql has date_add with different syntax.

To use a complex expression for a default value requires mysql 8 or mariadb 10.2+. And in mysql, the entire expression must be parenthesized.

You want:

default (date_add(current_timestamp, interval 30 day))
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