A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Head First Android
this week in the
Java in General
how to find differance between two dates excluding weekends
Joined: Aug 29, 2007
Nov 15, 2007 02:53:00
Excluding Saturday and Sunday, I want to calculate remaining days difference (count) in two given date objects. Please hit back ASAP.
Joined: Oct 27, 2005
Nov 15, 2007 03:21:00
Just an initial thought here.
First get the difference in dates including weekends:
Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); int days = cal1.get(Calendar.DAY_OF_YEAR) - cal2.get(Calendar.DAY_OF_YEAR); // if the years are different, correct it
Then subtract the number of weekends between them.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Joined: Oct 04, 2007
Nov 15, 2007 11:58:00
You may want to have a look at Joda Time, I believe some variation will be included with
1.7, and it makes for easy time/date calculations. I don't believe it will remove the weekends for you, but could make it a bit easier.
I agree. Here's the link:
subject: how to find differance between two dates excluding weekends
subtracting two dates
Frequently used word with friends
Calculating no. of working days between tow dates
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015