• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic