web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How can I Calculate days between 2 dates using a 360 day year

(0) ShareShare
ReportReport
Posted on by 1,025

Hello :)

is there any function in ax 2012 help me to calculate days between 2 dates using a 360 day year

Thanks 

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    299,349 Super User 2025 Season 2 on at
    RE: How can I Calculate days between 2 dates using a 360 day year

    Hi Source258147,

    Can you explain me what a 360 day year means for you? The date calculation provided by Crispin is using the Gregorian calendar.

  • source258147 Profile Picture
    1,025 on at
    RE: How can I Calculate days between 2 dates using a 360 day year

    Thanks Crispin John Augustine  for the help

    but i want  360 days per year not 365

  • source258147 Profile Picture
    1,025 on at
    RE: How can I Calculate days between 2 dates using a 360 day year

    Thanks André Arnaud de Calavon  for the help

    this is for customization porpose

    i need some thing like this

    www.techonthenet.com/.../days360.php

    this is the function in excel calc days in years as 360 days not 365 days

  • André Arnaud de Calavon Profile Picture
    299,349 Super User 2025 Season 2 on at
    RE: How can I Calculate days between 2 dates using a 360 day year

    Hi source258147,

    Or you have to find a component (dll) which can do help you, or you need to write your own function for this calculation. It is not a standard function in x++.

  • source258147 Profile Picture
    1,025 on at
    RE: How can I Calculate days between 2 dates using a 360 day year

    Thanks  André Arnaud de Calavon :)

  • Verified answer
    André Arnaud de Calavon Profile Picture
    299,349 Super User 2025 Season 2 on at
    RE: How can I Calculate days between 2 dates using a 360 day year

    Hi source258147,

    Based on this article, I have created an x++ method. You can copy it and test it in your environment. Based on various calculation methods available, you can adjust the coding a bit. Please test carefully, I'm not liable for any wrong days calculation. Use it at your own risk.

    public static Days Days360(StartDate _startDate, EndDate _endDate, boolean _european = false)
    {
        int     year1, year2;
        int     month1, month2;
        int     day1, day2;
        
        ;
        
        year1 = Year(_startDate);
        year2 = Year(_endDate);
        month1 = mthOfYr(_startDate);
        month2 = mthOfYr(_endDate);
        day1 = dayOfMth(_startDate);
        day2 = dayOfMth(_endDate);
        
        
        if (_european)    
        {
            // European: Starting and ending dates on the 31st become the 30th.
            if (day1 == 31)
            {
                day1 = 30;
            }
            
            if (day2 == 31)
            {
                day2 = 30;
            }
        }    
        else    
        {
            // US: If both start and end dates are last day of february, set day2 to 30 
            if (month1 == 2 && dayOfMth(_startDate + 1) == 1 &&
                month2 == 2 && dayOfMth(_endDate + 1) == 1)
            {
                day2 = 30;
            }
            
            // US: If start date is last of february, set day1=30
            if (month1 == 2 && dayOfMth(_startDate + 1) == 1)
            {
                day1 = 30;
            }
        
            // US: If day1 is 30 or 31 and day2 is 31, set day2 to 30
            if (day2 == 31 && day1 >= 30)
            {
                day2 = 30;
            }
            
            // US: If day1 is 31, set day1 to 30
            if (day1 == 31)        
            {
                day1 = 30;
            }
        }    
        
        // Add it all together and return
        return 360*(year2-year1) + 30*(month2-month1) + (day2-day1);
    }


  • André Arnaud de Calavon Profile Picture
    299,349 Super User 2025 Season 2 on at
    RE: How can I Calculate days between 2 dates using a 360 day year

    Hi Crispin,

    The 360 day calendar is often used in the financial/banking sector, but there are some variants. You can read about it on the page I shared above, but also Wikipedia. It is a method to have e.g. an equal amount of interest for each month.

  • source258147 Profile Picture
    1,025 on at
    RE: How can I Calculate days between 2 dates using a 360 day year

    Thanks, André Arnaud de Calavon :)

    I really appreciate your time and effort to help me

    I test it in many scenarios and it works perfectly with me in many cases

    I just did a small calculation. I add "+1" to get the same result like DAYS360 function in excel 
    https://www.techonthenet.com/excel/formulas/days360.php

    this is the code i use it if anyone like to test it in Job

    static void Job143(Args _args)
    {
        int     year1, year2;
        int     month1, month2;
        int     day1, day2;
        StartDate   _startDate = mkdate(31,12,2013);
        EndDate     _endDate   = mkdate(28,02,2019);
        boolean _european = false;
        
        year1 = Year(_startDate);
        year2 = Year(_endDate);
        month1 = mthOfYr(_startDate);
        month2 = mthOfYr(_endDate);
        day1 = dayOfMth(_startDate);
        day2 = dayOfMth(_endDate);
        
        if (_european)    
        {
            // European: Starting and ending dates on the 31st become the 30th.
            if (day1 == 31)
            {
                day1 = 30;
            }
            
            if (day2 == 31)
            {
                day2 = 30;
            }
        } 
        else    
        {
            // US: If both start and end dates are last day of february, set day2 to 30 
            if (month1 == 2 && dayOfMth(_startDate + 1) == 1 &&
                month2 == 2 && dayOfMth(_endDate + 1) == 1)
            {
                day2 = 30;
            }
            
            // US: If start date is last of february, set day1=30
            if (month1 == 2 && dayOfMth(_startDate + 1) == 1)
            {
                day1 = 30;
            }
        
            // US: If day1 is 30 or 31 and day2 is 31, set day2 to 30
            if (day2 == 31 && day1 >= 30)
            {
                day2 = 30;
            }
            
            // US: If day1 is 31, set day1 to 30
            if (day1 == 31)        
            {
                day1 = 30;
            }
        }
        
        // Add it all together and return
        // add +1
        info(strFmt("%1", (360*(year2-year1) + 30*(month2-month1) + (day2-day1))+1));
        
    }


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
NNaumenko Profile Picture

NNaumenko 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans