• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to find the difference between Dates

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the methods from java.util.Calendar
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check compareTo() method
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks All
 
My, my, aren't you a big fella. Here, have a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic