Statistics

Archives

Polls

Do you find the Information Useful?

View Results

Loading ... Loading ...

Calculate Begin and End Dates for Month/Year

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
0007    VA evt_Month_MNTH = date_month([BF jdInputDate])
0008    VA evt_CenturyYear_CENTYR = date_year([BF jdInputDate])
0009    //
0010    VA evt_StringDate_DESC = concat(concat(lpad([VA evt_Month_MNTH],'0',2),"/01/"),[VA evt_CenturyYear_CENTYR])
0011    //
0012    Convert String To Date Format Mask
           BF jdBeginDate <- jdConvertedDate_DRQJ
           VA evt_StringDate_DESC -> szStringToConvert_VC10A
           "OSASE" -> szFormatMask_VC09A
0013    BF jdEndDate = add_months([BF jdBeginDate],1)
0014    BF jdEndDate = add_days([BF jdEndDate],-1)
0015    //
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 = add_months([BF jdBeginDate],1)
0027       BF jdEndDate = add_days([BF jdEndDate],-1)
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.

Related posts:

  1. Changing the Century for Calendar or Defaults for Effective dates
  2. Convert UTC Time Format to Local Date and Time format
  3. Convert Julian Date to Gregorian Date (SQL)
  4. Send Email with PDF Output
  5. Set EnterpriseOne Applications to RUN on FAT CLIENT

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>