Find difference between two dates by elimating weekends

shankar reddy
Ranch Hand
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.

Paul Sturrock
Bartender
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.

Jan Cumps
Bartender
Posts: 2608
14
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?

Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
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.