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

Date and time in DB

 
Leena Diwan
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,

I want to store date in my DB table as dd-MM-yyyy HH:mm:ss.
Basically I want date and time also.

I used -
Java.sql.Date date = new Java.sql.Date(System.currentTimeMillis());

It is giving me date value in DB table field but not time..
what do I need to do for it?

1. I checked SimpleDateFormat. It does do the formatting but gives back String, I want a formatted Date object
2. Also, I checked to use java.sql.Timestamp - however it gives values till nano seconds, I want it till seconds only.

How do I get this?

Thank you in advance!

Regards,
Leena
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dates in databases do not have formats, they are usually stored as numbers. The SQL type DATE does not store time information so you will need to use timestamp (or your database equivalient thereof). If yuo don't to display fractions beyond seconds just format the timestamp when you display it.
 
Leena Diwan
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh ok..
I am trying that out. Thank you for the reply.

My requirement is extended to store timezone information also.
Do I store it as a separate field in DB?

Thank you.

Regards,
Leena
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leena Diwan wrote:Do I store it as a separate field in DB?

Yes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic