This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[MySQL] Storing UTC time in database  RSS feed

 
Saurabh Pillai
Ranch Hand
Posts: 529
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What datatype should I use to store UTC time? Is BIGINT correct choice?

Thanks
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so.

Have you considered standard MySQL date-time types (a DATETIME or TIMEZONE)? Are there any downsides to these types?

I don't use MySQL much, but from the documentation it looks like DATETIME does no time zone conversion on its values. So, if your application is going to store the dates/times in UTC and retrieve them in UTC, a DATETIME would look like a good choice.

If you use BIGINT, you'll have to invent your own convention of encoding the date/time into BIGINT (and back). That unnecessarily complicates things and makes the data in the database cryptic, in turn making everything (testing, debugging, manipulating data outside of your application) much harder.
 
Saurabh Pillai
Ranch Hand
Posts: 529
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read up on DATETIME and java.util.Date. DATETIME is just fine.

Thanks Martin.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!