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?
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().
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.
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().
In the MySQL documentation shows the following example: CREATE TABLE t1 ( ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, dt DATETIME DEFAULT CURRENT_TIMESTAMP );
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
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 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With