«

»

Dec 10 2009

Calculate Begin and End Dates for Month/Year

VN:F [1.9.22_1171]
Rating: 4.3/5 (3 votes cast)

EventsCalendarThere was a need to calculate the Begin and End dates from a given Period/Year combination or  to calculate the month’s begin and end dates from a given date.

Like if you are given
Inputs: Period=3, Year=9,
Output: Begin and End dates will be 03/01/2009 and 03/31/2009 respectively.

Similarly if you were given a date say – 2/17/2009, the return Begin & End dates will be 02/01/2009 and 02/28/2009.

So, a simple BSFN was built to do the same, I thought it might help so shared here. Please do reply with better options/logic if you have any for the purpose.

The Input Parameters are as follows (Parameter Name – DataType)

1. jdInputDate – DATE
2. mnMonth – NUMBER
3. mnCenturyYear – NUMBER

Output Parameters are

1. jdBeginDate – DATE
2. jdEndDate – DATE
3. cErrorCode – CHAR

 

Listing of ER for Named ER: N5500006

=======================================================================
     NAMED ER: Calculate Begin and End Dates for a Given Date
=======================================================================
     evt_StringDate_DESC
     evt_Month_MNTH
     evt_CenturyYear_CENTYR
0001 // ===================================================
0002 // Deepesh MD    							START
0003 // Calculate the Begin and End Dates for a given Date.
0004 // ===================================================
0005 // Get Begin End dates for Input Date
0006 If BF jdInputDate is greater than NULL DATE
0007    BF jdEndDate = last_day(BF jdInputDate)
0008    BF jdBeginDate = add_days(add_months(last_day(jdInputDate),-1),1)
0016 Else
0017    // Get Begin End Dates for Period/Year
0018    If BF mnMonth is greater than
        And BF mnMonth is less than or equal to "12"
        And BF mnCenturyYear is greater than
0019       //
0020       VA evt_Month_MNTH = lpad(BF mnMonth,'0',2)
0021       VA evt_CenturyYear_CENTYR = lpad([BF mnCenturyYear],'0',2)
0022       //
0023       VA evt_StringDate_DESC = concat(concat([VA evt_Month_MNTH],"/01/"),[VA evt_CenturyYear_CENTYR])
0024       //
0025       Convert String To Date Format Mask
              BF jdBeginDate <- jdConvertedDate_DRQJ
              VA evt_StringDate_DESC -> szStringToConvert_VC10A
              "OSASR" -> szFormatMask_VC09A
0026       BF jdEndDate = last_day([BF jdBeginDate])
0028    Else
0029       //
0030       //  ERROR, Either the Date or month/year should be passed
0031       //
0032       BF cErrorCode = "1"
0033       BF jdBeginDate = ""
0034       BF jdEndDate = ""
0035    End If
0036    //
0037 End If
0038 //

 

So hope this piece of logic helps many technical developers for getting the start & end Dates of a month.

Published under the license.

VN:F [1.9.22_1171]
Rating: 4.3/5 (3 votes cast)
Calculate Begin and End Dates for Month/Year, 4.3 out of 5 based on 3 ratings
(Visited 764 times, 1 visits today)

About the author

Deepesh M Divakaran

Deepesh MD is more of a Gizmo Geek, and a techie.
A very experienced Technical Consultant on Oracle JD Edwards EnterpriseOne, and OneWorld. As a consultant he has worked for wide range of industries, from Manufacturing, Media, Oil & gas etc. and has worked on re-engineering modules, and areas of customization.
With a touch of class and understanding towards what ever he does, he is often regarded by his colleagues as the one stop answer for all Technical/Software related queries.

6 comments

Skip to comment form

  1. mouly

    I would like to add a 4 line code to get Begin Date & End Date of a Period. Prerequisite for this is there should be correct data populated & maintained in F0008 – Date Fiscal Patterns & F0010 – Company Constants.

    Code to get Current Period Begin & End Dates for Company – 00311

    0001 VA rpt_szCommercialCompany_CO = “00311”
    0002 F0010.Fetch Single
    VA rpt_szCommercialCompany_CO = TK Company
    VA rpt_jdDatefiscalyearbeginsj <- TK Date – Fiscal Year Begins
    VA rpt_mnPeriodNumberCurrent_PNC BF jdDate
    VA rpt_Century <- BF mnCentury
    VA rpt_mnFiscalYear1 BF mnPeriodNo
    “1” -> BF cRetrieveF0008Records
    VA rpt_szCommercialCompany_CO -> BF szCompany
    VA rpt_Century -> BF mnCentury
    VA rpt_mnFiscalYear1 -> BF mnFiscalYear1
    PO jdFromDateForGLandVoucher <- BF jdPeriodBeginDate
    PO jdThruDateForGLandVoucher <- BF jdPeriodEndDate

    mouly
    8.12 version | 8.98 toolset

    VN:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
    1. mouly

      0001 VA rpt_szCommercialCompany_CO = “00311”
      0002 F0010.Fetch Single
      VA rpt_szCommercialCompany_CO = TK Company
      VA rpt_jdDatefiscalyearbeginsj <- TK Date – Fiscal Year Begins
      VA rpt_mnPeriodNumberCurrent_PNC BF jdDate
      VA rpt_Century <- BF mnCentury
      VA rpt_mnFiscalYear1 BF mnPeriodNo
      “1” -> BF cRetrieveF0008Records
      VA rpt_szCommercialCompany_CO -> BF szCompany
      VA rpt_Century -> BF mnCentury
      VA rpt_mnFiscalYear1 -> BF mnFiscalYear1
      PO jdFromDateForGLandVoucher <- BF jdPeriodBeginDate
      PO jdThruDateForGLandVoucher <- BF jdPeriodEndDate

      VN:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
      1. mouly

        0001 VA rpt_szCommercialCompany_CO = “00311”
        0002 F0010.Fetch Single
        0003 Separate the Year and Century form 4 byte year
        0004 Calculate Begin Date of Period

        VN:F [1.9.22_1171]
        Rating: 0 (from 0 votes)
  2. Sudhakar Motade

    Hi Deepesh,

    I have Question about Date

    I stored one Date in variable and using that date i want to find out previous date….

    for Ex. variable A=10th aug 2012

    so in Variable B=9th Aug 2012

    please Suggest

    Thanks,
    Sudhakar

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
    1. Deepesh M Divakaran

      Hi Sudhakar,
      You may use the Add Days System function, to add “-1” day to it.

      VN:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  3. Sudhakar Motade

    Hi Deepesh,

    Thanks…. it working……

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a Reply