Not to beat a dead horse because Hunter2's solution is more efficient than mine, but my code should work. For example, say we are finding the number of days between May 1st to April 1st which is a difference of 335 days. Ok, day1 would equal 121 and day2 would equal 91. The variable x would start at 121 and increment, when it hits 365 it will revert to zero since 365%365==0. At this point the loop would have executed 244 times thus numdays will equal 244. Now the loop will keep executing 91 more times incrementing numdays 91 more times at which point x will equal day2. So numdays will have a grand total of 244+91=335 which is the correct answer.