• Post Reply Bookmark Topic Watch Topic
  • New Topic

[MySQL] Storing UTC time in database

 
Saurabh Pillai
Ranch Hand
Posts: 527
  • 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: 527
  • 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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!