• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date and Time  RSS feed

 
Kedar Dravid
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is the best design technique to store time values(date & time string) in the database? Is it using single datetime datatype or using two different datatypes to store date and time string seperatly?
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most databases support a datetime or timestamp datatype directly. If this is an option, avoid using strings as they cannot be ordered easily (unless you choose a workable format). JDBC supports DATE, TIME, and TIMESTAMP. If your value represents a point in time, don't split it up.

Of course, you'll always be able to find a case where separating them is a better choice. In the end you have to use your best judgment which usually comes from making the wrong choice and learning from your mistake.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!