Reputation: 87
I have one questions regarding storing date in mysql database. Here is it :
Is it good to store date in INT
(milliseconds) format rather than yyyy-mm-dd hh:mm:ss format?
So for example, at a time of writing question, the datetime is 2016-02-05 12:19:46. Is it good idea to store this datetime in database in INT means millisecond (1446xxxxxxx) format? Will it increase my db performance?
Upvotes: 4
Views: 2622
Reputation: 2373
No, it's not good practice to store date in integer format(milliseconds). Because whenever you'll need date from database you've to convert it back into Date Format and it'll affect your application's performance. And When talking about Db's performance it'll be constant as there wouldn't much affect but it'll be a bottle neck for you to retrieve date from database and convert back to date format and represent or use in your application.
But you can do it if you're in really need of it. As i'm unknown to your scenario of application and it's usage.
Upvotes: 2
Reputation: 172548
This might be a opinion based question but my pick is that you should avoid storing dates as int(in unix time format). As it would become really a tedious task everytime you want to fetch your date and display it in a format to be readable.
As far as the performance is concerned it will depend on your usage. As a matter of fact int datatype is half the size of datetime. Also when it comes to sorting then int can be faster when compared to date datatype(Didn't test). Also the performance of date datatype is faster than the int datatype. But when it comes to formatting the date which you would want after selecting them and for display purpose, it will be difficult and an unnecessary overhead.
Upvotes: 1