• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

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
Hi,
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


 
Bartender
Posts: 4179
22
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
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic