Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[MySQL] Storing UTC time in database

 
Saurabh Pillai
Ranch Hand
Posts: 524
  • 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: 524
  • 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