PowerBuilder Function Relative Month gf_relative_month
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : gf_relative_month // Argument Name : ad_source, Arg Type : Date, Pass By : Value // al_month, Arg Type : Long, Pass By : Value // Return Type : Date /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Given a date, will return the date +/- the number of months passed // in the second parameter. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Integer li_adjust_months Integer li_adjust_years Integer li_month Integer li_year Integer li_day Integer li_temp_month //Check parameters If IsNull(ad_source) Or IsNull(al_month) Then Date ldt_null SetNull(ldt_null) Return ldt_null End If //Check for invalid date If Not f_Is_Valid_Date(ad_source) Then Return ad_source End If //Number 12 is for the Twelve months in a year. li_adjust_months = Mod(al_month, 12) li_adjust_years = (al_month / 12) li_temp_month = Month(ad_source) + li_adjust_months If li_temp_month > 12 Then // Add one more year and adjust for the month li_month = li_temp_month - 12 li_adjust_years ++ ElseIf li_temp_month <= 0 Then // Subtract one more year and adjust for the month li_month = li_temp_month + 12 li_adjust_years -- Else // No need for any adjustments li_month = li_temp_month End If li_year = Year(ad_source) + li_adjust_years li_day = Day(ad_source) //Check for a valid day (i.e., February 30th is never a valid date) Do While Not f_Is_Valid_Date(Date(li_year, li_month, li_day)) And li_day > 0 li_day -- Loop Return( Date(li_year, li_month, li_day)) |
Good Luck!
Subscribe
Login
0 Comments