Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calculate weeks between 2 dates

 
Joel Carklin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Thanks
Joel
 
Vladan Radovanovic
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

kawaii
[ February 25, 2002: Message edited by: kawaii desu ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joel Carklin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic