F_RELATIVE_YEAR

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Name : f_relative_year
// Argument Name : ad_source, Arg Type : Date, Pass By : Value
//                           al_years, Arg Type : Long, Pass By : Value
// Return Type : Date
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//    Description:   Given a date, will return the date +/- the number of years passed
//                        in the second parameter.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
integer li_year
integer li_month
integer li_day

//Check parameters
If IsNull(ad_source) or IsNull(al_years) 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

li_year = Year(ad_source) + al_years
li_month = Month(ad_source)
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))

0 comments:

Post a Comment