• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Date and time in DB

 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 42011
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leena Diwan wrote:Do I store it as a separate field in DB?


Yes.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic