# Java calendar calculate days between two months

Hi Experts:
I have one final problem that I need help with.  I need to calculate the number of days between two months.
I have two dates:
start: 11/16/2010
end: 12/01/2010

I need to calculate the number of days between these two months.  In this case, the answer would be: 16

[i]BUT [/i]It can get tricky if the dates are like this:
start: 11/15/2010
end: 12/21/2010

In this case the number of days is 6.  The reason why it should be 6 is because it's 1 month + 6 days.
Tricky, I know!
###### Who is Participating?

Commented:

If the date of the end date is greater than or equal to the date of the beginning date, then simply subtract the two dates (21-15=6).

If not, then add the date of the end date to the length of the month prior to the end date, and then subtract the dates ((1+30)-16=15).

Note that there is discrepancy in how your counting days in the two cases. If that is intentional you will have to compensate by adding a day in the second case.
0

Commented:
Correct me if i'm wrong but isn't this being done for the purposes of billing?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.