• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple logic for getting the no.of "Day" s between 2 dates

 
Swapna Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could any one tell me a simple logic to get No.of DAY's between 2 dates?
Example:
Start date:22/03/04
EndDate: 22/03/03
I want to get No. of SUNDAY's between these two dates.
Could any one tell me simple logic?
Thanks
--swapna
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy. Here's some logic for ya:
Calendar start = GregorianCalendar set to 22/03/04
Calendar end = GregorianCalendar set to 22/03/03
int count = 0
while(start < end)
get day of week of date in start,
if day matches Calendar.SUNDAY increment count by one
increment start by one day

You'll have to decide whether to include the start and end days in the calculation, which means adjusting the start day and the comparison between start and end as appropriate.
Now get coding!
[ March 22, 2004: Message edited by: Carlos Failde ]
 
Swapna Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic