• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Comparing java.Util.Date SQL Date  RSS feed

Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • 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: 4181
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!