You have to do this piecemeal so there isn’t a single formula. The best way is to convert each date using a common frame of reference. Dates before October 1582 used a different calendar. Also the distance between leap years varies. It’s normally 4 years but it can be 8 years. For example, 2100 is not a leap year but 2096 and 2104 are both leap years. Similarly 1896 and 1904 but not 1900. Before October 1582 leap years occurred exactly 4 years apart. Your next problem is to work out the day number from the beginning of the year. On average there are between 30.4 and 30.5 days in a month, but this is only an approximation because the length of each month varies. So to aid in the calculation you need a table which gives you the day number for every date in the year, and the table is different for leap years. So, you start by subtracting the years and counting how many leap years there are between. You consult the day number table for working out how many days there are from the beginning of the year. Another way is to have a smaller table with just the months, so in a non-leap year Jan 1 would be 1, Feb 1 would be 32, Mar 1 would be 60, Apr 1 would be 91, and so on. Then we have to add in the day date. Mar 20 would be 19 days after Mar 1 so would have a day number of 79, not 80. Some diaries and calendars include the day number. You can speed up the calculation by using one day number table or calculation and then adding in a day for each leap year between two dates. I hope this helps.