Difference between dates using a 360 day calendar





5.00/5 (1 vote)
DAYS360 excel function
Introduction
Many financial calculations between dates require that days are calculated using a 30 days month (360 days year)
You can find additional information in wikipedia here
To do that, there is an excel function Days360. Unfortunately, it requires that your application includes excel libraries.
This application implements C# code that does that calculation and test it against excel.
Problem Logic
There are two cases to consider:- When the month and year of both dates are the same.
- When the month and year are different.
- From the day of DF to 30 of the same month (30 - Day(DF))
- Complete months of 30 days
- From 1 to the day of DT of the month of DT
Special cases
There are special cases to consider when the day from the date from is 31 or the month is February.For that cases, there are two methods:
The European Method (30E/360):
- If either date A or B falls on the 31st of the month, that date will be changed to the 30th.
- If both date A and B fall on the last day of February, then date B will be changed to the 30th.
- If date A falls on the 31st of a month or last day of February, then date A will be changed to the 30th.
- If date A falls on the 30th of a month after applying (2) above and date B falls on the 31st of a month, then date B will be changed to the 30th.
Improvements
The logic is not optimized for speed. The function returns 0 when the date from is greater than the date to (excel returns negative values).Source code
The source project is VS2008 and uses Framework 2.0.
It also uses Microsoft.Office.Interop.Excel.dll to validate the function
History
- 2013-03-04. First version.