Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL datetime default time with interval

Is it possible to add to a default time with NOW(), 10 minutes?

I've tried something like that:

CREATE TABLE `table1` (
    `date` DATETIME NOT NULL DEFAULT DATE_ADD(NOW(), INTERVAL 10 MINUTE)
);  

However, it doesn't work.

like image 243
loop Avatar asked Mar 02 '26 09:03

loop


1 Answers

I dont think you can do this.

The MySQL Documentation states that:

The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column

like image 117
David Steele Avatar answered Mar 05 '26 03:03

David Steele



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!