File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to find the difference between Dates

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i have to allow the user into Database table ,who is having minimum 1year service in a company..

for that i have to find today date and user's date of join from database..

and then subtract..right? but..i confuse..how to do it?..how to find the difference between two days?

Thanks & Regards,
seetharaman.v
 
Jhakda Velu
Ranch Hand
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Why don't you handle this in your query itself?
Sysdate will give you current date and time, and the date of joining that would have been stored in the table can be subtracted. If its stored as Varchar(instead of date) use the inbuilt to_date function.
This, alongwith a bit of googling will get you through.

Jhakda
 
Rodrigo Lopes
Ranch Hand
Posts: 119
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the methods from java.util.Calendar
 
Manuel Leiria
Ranch Hand
Posts: 171
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check compareTo() method
 
Alan Christen
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Google query

http://www.google.com/search?hl=en&q=how+to+find+the+difference+between+Dates+%2Bjava&btnG=Google+Search

returns 242,000 hits.

In this *huge* result set, I found this url:

http://www.exampledepot.com/egs/java.util/CompDates.html

Time spent: 3 minutes.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alan Christen:
The Google query

http://www.google.com/search?hl=en&q=how+to+find+the+difference+between+Dates+%2Bjava&btnG=Google+Search

returns 242,000 hits.

In this *huge* result set, I found this url:

http://www.exampledepot.com/egs/java.util/CompDates.html

Time spent: 3 minutes.

There is one problem with that code: it is defective because of daylight savings time. Because of that, days can have 23 or 25 hours as well.


Using Calendar.get(Calendar.DAY_OF_YEAR) and Calendar.get(Calendar.YEAR), combined with Calendar.getActualMaximum(Calendar.DAY_OF_YEAR), you can calculate the result more precisely. Search on this forum, I've answered this question at least 3 times already.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks All
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic