aspose file tools
The moose likes JDBC and the fly likes Find difference between two dates by elimating weekends Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Find difference between two dates by elimating weekends" Watch "Find difference between two dates by elimating weekends" New topic
Author

Find difference between two dates by elimating weekends

shankar reddy
Ranch Hand

Joined: Jun 04, 2007
Posts: 71
Hello Ranchers,

I want to find the difference between two dates which should eliminate weekends . I am using Oracle 10g. Could anybody help me out.


Java Lover<br /> <br />Shankar Reddy <br />SCJP1.4 (88%)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

In Java, what you could do is create a Calendar for the first date, a Calendar for the second, create a loop to run while the first date is before the second and call add() to add a day at a time to the first date. Then you can check whether the first date is a weekday and increment a count to measure the difference.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2343

It must be possible to calculate this with an algorithm in stead of a loop.
Unfortunately I can't come up with a reasonable one for the moment.
Where are the Math wizards?


OCUP UML fundamental
ITIL foundation
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26138
    
  66

Originally posted by Jan Cumps:
It must be possible to calculate this with an algorithm in stead of a loop.

Dividing by 7 gets you close to the number of weeks. Then adding some logic for what day of the week you are starting and ending on gives you the details. If the dates aren't far apart, the loop seems easier. If they are far apart, it's more likely to be worth figuring out the details of the algorithm.

This all assumes that Shankar is using JDBC and not just an Oracle query.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find difference between two dates by elimating weekends
 
Similar Threads
How to calculate difference between two dates in months
how do I find date difference in months
about dates
Oracle Date Difference Excluding Weekends
difference between two dates