If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Embedded Database Design Concern RE:Dates

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-07, 21:57
loproman loproman is offline
Registered User
 
Join Date: Dec 2007
Posts: 3
Embedded Database Design Concern RE:Dates

Hello,

I'm working on a project where the database is embedded in the application and distributed to clients. I have a concern related to dates/times that I'd like to put out there.

I'm thinking that dates and times should be stored in some locale neutral way. This is because as a distributed application, the database is very likely to change timezones much more frequently than a traditional client/server model. For instance if the software is running on a laptop, one day the database may be in San Diego, the next day it may be in Japan.

How should I store the date? Should I convert it to GMT:00 before it goes to the db? Is it better to use an "Epoch" and just store the date as a long?
Reply With Quote
  #2 (permalink)  
Old 12-05-07, 22:42
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
My answer is to use GMT... You can easily convert local time to GMT at the point of capture, but there is always uncertainty from that moment onward. Once you have the data stored using GMT for times and dates, you can easily convert it back to local time for presentation, regardless of what "local time" is at the moment!

-PatP
Reply With Quote
  #3 (permalink)  
Old 12-05-07, 22:56
loproman loproman is offline
Registered User
 
Join Date: Dec 2007
Posts: 3
What about just using a long value?

Ok. Thanks! Helps to know I'm thinking of the problem in the right way.

Let me bounce another crazy idea off of you. I'm using Java, and will almost certainly continue using Java. In case you're not familiar, the Date object is basically a wrapper around a long value representing milliseconds from "00:00:00 GMT on January 1, 1970"

I'm thinking about just storing the long value instead of enduring all of the date conversion BS. Like you said, it's more a matter of how I spit it back out to end user. To my knowledge, this really only changes the DB schema from TIMESTAMP (I'm using Derby) to a long value. I think queries/sorting would still be pretty natural since the long value still represents a fairly distinct point in time.

I'm a little unsure of myself here because I'm wondering if there are other advantages to using the database TIMESTAMP that I'm not considering. Like I said however, I think it is probably more simple than date math in Java.
Reply With Quote
  #4 (permalink)  
Old 12-05-07, 23:06
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
The primary advantage that I see in using the TIMESTAMP datatype is that there is no reasonable explanation for mistaking it for anything else... Nobody can reasonably claim "It was a long, so I did math with it" and not understand the consequences.

If and when you need to convert to another database engine (any program that lives long enough will have to swtich database engines, it is a law of nature), the TIMESTAMP datatype almost always makes that conversion more straightforward.

-PatP
Reply With Quote
  #5 (permalink)  
Old 12-06-07, 01:02
loproman loproman is offline
Registered User
 
Join Date: Dec 2007
Posts: 3
Cool. I hear you on the concern about mistaking the integer value for something else. That's a very legitimate point.

Not sure I can think of any scenarios where converting a long value between database engines would be that tough. Would you be kind enough to elaborate?
Reply With Quote
  #6 (permalink)  
Old 12-06-07, 07:21
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
If you are manually doing the conversion, one column at a time, then there is no problem. I'm thinking about when you need to convert lots of columns (say over 250,000 columns), like in a PeopleSoft database.

Automated tools have a hard time distinguishing between an I8, an *ix ephoch, and a GIS locator code even though all of them are stored in a 64 bit integer. You could simply "move" the columns to the new database engine, but you'd need a pretty sophisticated ETL tool to read or infer enough metadata to handle them correctly if you wanted to do anything more than just "pick 'em up an' put 'em down" as you went from one database engine to another.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On