File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes calculate weeks between 2 dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "calculate weeks between 2 dates" Watch "calculate weeks between 2 dates" New topic

calculate weeks between 2 dates

Joel Carklin

Joined: Jun 15, 2001
Posts: 28
Can someone please explain to me how I would calculate the number of weeks between two dates. I know I would be using the calendar class but I've got myself into a muddle!
Any assistance apreciated
Vladan Radovanovic
Ranch Hand

Joined: Mar 20, 2000
Posts: 216
For example, you can get time for both in milliseconds and then subtract one from the other. From there get number of days/weeks.
Alex Ku
Ranch Hand

Joined: Jan 15, 2002
Posts: 47
In Calendar class, there is a static field - WEEK_OF_YEAR.
So, you just need to find the week of year of two input dates and do a substraction (make sure the input dates are in the same year).

[ February 25, 2002: Message edited by: kawaii desu ]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
You also need to decide what you really mean when you say "number of weeks" between two dates. How many weeks were there between Friday, Feb 22, and Monday, Feb 25? 1? 0? 0.4286? What about between Monday Feb 25 and Thursday Feb 28? Does the answer change? The way you want to answer these questions will determine how you do the calculation.

"I'm not back." - Bill Harding, Twister
Joel Carklin

Joined: Jun 15, 2001
Posts: 28
Thanks for all your help.
I agree. Here's the link:
subject: calculate weeks between 2 dates
It's not a secret anymore!