Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not use datetime type in mysql workbench

Tags:

datetime

mysql

I have tried to make a column using datetime type in MySQL workbench.
but, when I select datetime type it occurs an error like

Could not set new data type The given data type DATETIME contains errors and cannot be accepted. The previous value is kept instead"

How can I use this type?

like image 426
Jaeyoung Lee Avatar asked Mar 18 '16 07:03

Jaeyoung Lee


People also ask

How do I insert a datetime in SQL Workbench?

To insert only date value, use curdate() in MySQL. With that, if you want to get the entire datetime, then you can use now() method. Insert both date and time with the help of now().

Does MySQL support date data type?

MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' . The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format.

How do I change the date format in MySQL workbench?

Change the curdate() (current date) format in MySQL The current date format is 'YYYY-mm-dd'. To change current date format, you can use date_format().

How can create date and time table in MySQL?

In the MySQL documentation shows the following example: CREATE TABLE t1 ( ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, dt DATETIME DEFAULT CURRENT_TIMESTAMP );


2 Answers

I had this problem, you need to make sure that when you select the data type you change datetime() to datetime with no ().

From MySQL 5.6.4 onwards DATETIME can have subseconds, the level of precision being defined in the (), if you are not using subseconds then simply remove this all together. This also applies to the TIME and TIMESTAMP Datatypes.

For more info see here

like image 51
Justin Avatar answered Oct 17 '22 22:10

Justin


As of 5.6.4 TIME, TIMESTAMP and DATETIME can have a fractional part. To create a field with subseconds you can specify precision in brackets: TIME(3), DATETIME(6) etc.

time(3)      = 05:05:10.000 (3 precision )
timestamp(6) = 2013-07-04 05:05:10.000000 (6 precision )
datetime(1)  = 2013-07-04 05:05:10.0 (1 precision )
datetime     = 2013-07-04 05:05:10 (0 precision )
like image 26
Muhammad Faizan Fareed Avatar answered Oct 17 '22 21:10

Muhammad Faizan Fareed