This problem has been addressed six weeks ago on this site. I give you the link to the post and answers.
Subtracting two dates
It is not a trivial problem at all (in particular because of the leap years) and I think that the easiest way to solve it is to go through Julian day numbers and perform substraction. Programming this is quite simple (if you need a piece of code, I could make one for you).
Added later
Searching in my notes, I found something (I do not remember where in the Internet) that I put between quotes (I put in bold what I think important) :
"First of all, since February is an especially short month, it is
normally better to consider January and February the 13th and 14th
months of the previous year. So first, if the month is 1 or 2, then
you add 12 to the month and subtract 1 from the year. Then the day
is
365*year + year/4 - year/100 + year/400 + date + (153*month+8)/5
where all of the divisions are rounded DOWN to the nearest integer
.
Do this for both dates, and subtract."
Do not forget to use the floor of the result of any division.
year/4−year/100+year/400. – eatSleepCode Feb 20 '14 at 09:11