0

I have the following create table statement (in MySQL):

CREATE TABLE bugs (id INT, open_date DATE, 
close_date DATE DEFAULT STR_TO_DATE('9999-99-99', '%Y-%m-%d'), severity INT); 

Unfortunately, it is not working and returns an error because of the default date value. Any other way to set a particular default value to date when using the create table statement? Thanks in advance.

mj1261829
  • 1,200
  • 3
  • 26
  • 53

2 Answers2

0

Try this

CREATE TABLE bugs (id INT, open_date DATE, 
close_date DATE DEFAULT '9999-99-99', severity INT); 

for more information, use the below link:-

How do you set a default value for a MySQL Datetime column?

Community
  • 1
  • 1
Munish Chouhan
  • 318
  • 4
  • 10
0

MySQL's default DATE field format is YYYY-MM-DD. The supported range is 1000-01-01 to 9999-12-31. But you can't insert only date there,You need timestamp here

CREATE TABLE bugs
      (id INT, open_date DATE, 
       close_date TIMESTAMP DEFAULT '2016-11-30 22:30:00',
       severity INT
      );

Fiddle here

Since MySQL 5.6 DATE should work with default value NOW()

For more on Mysql dates read this

Shivkumar kondi
  • 6,458
  • 9
  • 31
  • 58