my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Simple logic for getting the no.of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple logic for getting the no.of "Day" s between 2 dates" Watch "Simple logic for getting the no.of "Day" s between 2 dates" New topic
Author

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

Swapna Agarwal
Ranch Hand

Joined: Jan 30, 2004
Posts: 37
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

Joined: Oct 20, 2000
Posts: 84
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

Joined: Jan 30, 2004
Posts: 37
Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple logic for getting the no.of "Day" s between 2 dates
 
Similar Threads
Subtracting Dates in JAVA
How to get the Dates in-between two Dates
Difference between two dates
No.of SUNDAY's between two dates???
how to find number of sundays and saturdays between two dates