This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Simple logic for getting the no.of Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Simple logic for getting the no.of "Day" s between 2 dates
 
Similar Threads
how to find number of sundays and saturdays between two dates
How to get the Dates in-between two Dates
Difference between two dates
No.of SUNDAY's between two dates???
Subtracting Dates in JAVA