• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Comparing java.Util.Date SQL Date

Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my Database I have saved a list of Documents and their creation Time. The time is displayed in this format YYYY-MM-dd HH-mm-ss
In my program, I am required to get the list of documents created on a particular date(say today) and save it in a text file. In order to do so, I have compare the current date and the date of creation of all documents in my data base. I get the current Date using java.util.Date which is also displayed in the same format ( YYYY-MM-dd HH-mm-ss). only when I am comparing uisng the YYYY-MM-dd HH-mm-ss format, I am comparing time as well, which poses a problem., since i am required to compare only dates.
For the current date I can change the date format to simply YYYY-MM-dd but I cannot do the same for the creation time in the database.
how do i deal with this problem?
Any help is much appreciated .
Have a nice day

Posts: 4179
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way I see it there are three ways of doing this:

1) Use SimpleDateFormat to convert all incoming Dates to Strings in the format you want. Compare the Strings.

2) Turn each Date into a Calendar. Get the Year, Month, and Day values from the Calendar and compare them.

3) Use a third party library which makes working with Times and Dates a whole lot easier, like Joda Time
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic