Cogita Tute! - think for yourself      |   Login   |      |   September 08, 2008   
 
Ta vouna - Ida mountains
 
DAYS360 Function

I know that this is not a mainstream issue, but those who are familiar with Excel's DAYS360 function would know this problem.

Shortly, "DAYS360" is an Excel function that calculates the number of days between two dates, regarding that each month is composed of 30 days. This feature is generally used in financial markets.

While I was dealing with Bloomberg API integration with a C# code, I faced the problem. One of my friends shared his formula of calculating the correct interval. This is the way Bloomberg system calculates DAYS360 style date intervals :

        public static int CalculateDays360(DateTime d1, DateTime d2)
        {
            
int years d2.Year - d1.Year;
            int 
months d2.Month - d1.Month;
            
            int 
dayNo1 0;
            int 
dayNo2 0;

            
dayNo2 d2.Day;
            
dayNo1 d1.Day;

            if 
(dayNo1 == 31) dayNo1 30;
            if 
(dayNo2 == 31) dayNo2 30;

            int 
days dayNo2 - dayNo1;
            return 
years * 360 + months * 30 + days;
        
}

Use it with your own risk.

I checked it with numerous date intervals of real Bloomberg data. It worked without exception.

But beware : It doesn't work the same way that Excel calculates it. But from internet forums, I understand that not all of the users are happy with Excel 's way of calculating DAYS360 either. Maybe our function helps you.

Here's a Visual Studio 2005 project, in which I demonstrate how to use it.


Snapshot of the VS project

Snapshot of the program
Download VS 2005 Project Files
 TitleOwnerCategoryModified DateSize (Kb) 
VS2005 ProjectBilgin Esme 6/21/200734.73Download

Bilgin Esme, Jun 2008
Your feedback is welcome



Cancel   Send
Crumpler Wee Bee

 


My Crumpler Wee Bee


For my quest of the ideal notebook bag and my review of Crumpler Wee Bee, click

Wee Bee review

Programmer's Blog

 

Programmer's Blog


Specific hints and tricks for C# programmers.

click here

Bicycle in January

 

Bicycle in January


Impressions after a bicycle tour in a warm January Sunday (!). On the bicycle routes of Istanbul and Bagdat Caddesi.

Bicycle in January

  You are here :- Bits & Bytes >> Programmer's Blog >> Articles >> DAYS360 Function