What should the Length/Value be for “DATE” data type in mysql?

I looked for the answer to this question before posting this but I couldn’t find it. I’m sorry if it has been asked before but I would like to know what I should enter for the Length/Value for “DATE” in mysql.

Thanks in advance

What should the Length/Value be for "DATE" data type in mysql?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You don’t need to provide a length. Just do:

create table test (
 id int,
 created_date date,
 modified_date date
);

See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-type-syntax.html for documentation.

You can insert data with insert into test values (1, '2020-01-01', '2020-02-01');

Method 2

”’
select data type DATETIME for date. mysql will autumatically reserve 3 bytes of space for date and several date format is available in my sql. for eg datestamp, Dateonlyformat.
create table abc (
id int,
registrationDate date
);
”’


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x