Sitemap
Ted James

Ted James

The world is my office, and every destination is my inspiration

CURRENT_DATE/CURDATE() not working as default DATE value

1 min readJun 26, 2024

Pretty straight forward question here, I think this should work but it doesn’t. Why doesn’t it?

CREATE TABLE INVOICE(
INVOICEDATE DATE NOT NULL DEFAULT CURRENT_DATE
)

Solution

[Edit] As of MySQl 8.0.13 it is supported. See this answer below.

Get Ted James’s stories in your inbox

Join Medium for free to get updates from this writer.

It doesn’t work because it’s not supported

The DEFAULT clause specifies 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

Answered By — zerkms

Answer Checked By — Robin (FixIt Admin)

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

creative-commons-by-21pxcreative-commons-sa-21px

--

--

Ted James
Ted James

Written by Ted James

The world is my office, and every destination is my inspiration