ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Fiscal Calendar

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fiscal Calendar

    Hi,

    I need an algorithm to help me determine when the start and end date for my fiscal period.

    My fiscal period starts at the 26th and ends on the next month on the 25. For example today's date = 10/27/2008 , the fiscal start would be 10/26/2008 and the ending date would be 11/25/2008.

    Does anyone have an idea how I would code for it?

    Thanks,

    DAC

  • #2
    Re: Fiscal Calendar

    Here's a function that returns the end of month date for a passed date. It will give you an idea of what to do:

    Code:
            //* * * * * * * * * * * * * * * * * * * * * * * * * * * *
            //
            // EndOfMonth - Returns the End Of Month Date
            //
            //  Parameters
            //  PassedDate - A date Field
            //
            //  Returns
            //  The End Of The Month Date For the Passed Date
            //* * * * * * * * * * * * * * * * * * * * * * * * * * * *
    
         p EndOfMonth      b                   export
         d EndOfMonth      pi              d
         d  PassedDate                     d   const
    
         d  EomDate        s               d
    
          /free
    
           // Convert the date to the end of the month
    
             EomDate = PassedDate + %months(1) - %days(%subdt(PassedDate:*d));
    
            return (EomDate);
    
          /end-free
         p                 e
    This is the code snippet that converts a date to the end of the month:
    EomDate = PassedDate + %months(1) - %days(%subdt(PassedDate:*d));

    This code will add 1 month to the date, then subtract the number of days in the date that was passed. If the date we passed was 10/27/2008, then EomDate will contain 10/31/2008.

    To do you what you want to do, I would create two functions like the one above. One function would return the Fiscal Start Date. The Second would pass the Fiscal End Date.

    To get the fiscal start date, the first thing the function should do is to examine the DAYS portion of the date that was passed to it. If DAYS < 26, then the fiscal start date would be 1 month less than the current date, and the day would be set to 25. If DAYS >= 26, then the fiscal start date would be set to the 25th day of the current month.

    Code:
         
            if %subdt( PassedDate : *d ) < 25;
              FiscalStartDate = PassedDate - %months(1);
            endif;
    
              FiscalStartDate = PassedDate - %days(%subdt(PassedDate:*d)
                                           + %days(25);    
    
               return (FiscalStartDate)
    In the above example, if the day of the month is less than the 25th of the month, we subtract 1 month from the date. Otherwise the month remains the same.

    Then we subtract the day of the month from the date, and add back in 25 days so that the date is set to the 25th.

    I havent completely checked this code over, but you should get the idea. You can use the similar techique to calculate the fiscal end date.

    You will likely want to package these functions in a Service Program.

    You also should hire someone to beat the snot out of whoever created these whacked fiscal start and end dates.
    Last edited by MichaelCatalani; October 27, 2008, 09:45 AM.
    Michael Catalani
    IS Director, eCommerce & Web Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

    Comment


    • #3
      Re: Fiscal Calendar

      dcutaia, it sounds like you already know your fiscal cycle so why not just code up a loop or something that takes the current month and just adds or subtracts months. Hard code the begin day as 26 and then end day at 25. Then just add and subtract *month. Seems pretty simple. If you are using Date fields this would be very easy to do.
      Your future President
      Bryce

      ---------------------------------------------
      http://www.bravobryce.com

      Comment

      Working...
      X