Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ralated to date  RSS feed

 
shubhank khare
Greenhorn
Posts: 15
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i m developing a auction site in which for remaining time i need to compare database date to current system date.anybody suggest me the code for that.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubhank,
Welcome to CodeRanch!

You can get the database date in a query via JDBC. The exact query varies by database. Then you have both dates in Java memory and can compare. Note that it is likely that the application and database server are slightly different under the best of circumstances.
 
shubhank khare
Greenhorn
Posts: 15
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Shubhank,
Welcome to CodeRanch!

You can get the database date in a query via JDBC. The exact query varies by database. Then you have both dates in Java memory and can compare. Note that it is likely that the application and database server are slightly different under the best of circumstances.


thanks Jeanne, but i have current date java.util type and get database date in other format than can i compare both day by day.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be a bit more specific; how are you getting the date from the database, and how exactly do you want to compare it to the current date? Where exactly do you get stuck with this problem?

Normally, you'd get a java.sql.Date from the database (which is a subclass of java.util.Date). The java.util.Date class has methods to check if another date is before or after the Date object you're calling it on.
 
Pat Farrell
Rancher
Posts: 4686
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be more specific on what precision and accuracy you need?

For example, a lot of applications really need to know that one date is earlier than another, at millisecond precision or better, but don't actually care about the accuracy of the time, it could be even an hour off of "official" time, and the application would work just fine.

Others want the time to be correct, in sync with say the astronomical time, so you can point your telescope at the right part of the sky, but don't care about precision under a second.

Java's built in date/time code is actually fairly weak at providing either at high scaling rates.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!