You need two arrays one for a normal year and one for a leap year that contain the number of days in each month so you can add up the days in the year.

January will be zero because you don't have to add and days for previous months, but februrary will be 31 because the first of feb is day 32 ie 31+1
j f m a m j j a s o n d
0, 31 28 31 30 31 30 31 31 30 31 30
so for 18 july (7th month) you add up the first 7 numbers and add 18

to save adding you coudl cummulatvely add the days
0, 31, 59, 90, 120, 151 181 212 243 273 304 334

SO from the above if you have 27 dec you add 27 to the the 12 element (334) to get 361

Us this array for a leap year.
0, 31, 60, 91, 121, 151 182 213 244 274 305 335

Then using your function to determine is a year is a leap year populate a table add the number of days up between the two years in question and add the difference in the number of days (which will be negative in some cases)