Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between DATETIME and DATETIME()

This may seem like a trivial question, but I took a look at all the available datatypes for dates available in sql and I saw some thing that I needed clarification on. I searched several posts for possible answers, but nothing remotely talked about it.

So my question is:
What makes DATETIME and DATETIME() different?

Should they be treated the same way as you treat variables and methods respective in Java?

like image 274
CODI Avatar asked Nov 22 '25 05:11

CODI


1 Answers

The difference is the precision. In MySQL 5.6, for example, DATETIME only stores whole seconds. Fractions are only supported if you use DATETIME(6).

If you access columns with DATETIME or DATETIME(6) types through JPA, most likely you would be mapping them to Date objects and in my experience you can treat them the same way (except that you won't get fractions of seconds with DATETIME).

like image 156
thinker Avatar answered Nov 24 '25 17:11

thinker