of_relativemonth


pfcapsrv.pbl   >   pfc_n_cst_datetime   >   of_relativemonth   

Full name pfc_n_cst_datetime.of_relativemonth
Access public
Extend of date
Return value date
Prototype public function date of_relativemonth(date,long)

Name Datatype
No Data

Name Datatype
ldt_null date
li_adjust_months integer
li_adjust_years integer
li_day integer
li_month integer
li_temp_month integer
li_year integer

public function date of_relativemonth (date ad_source, long al_month);//////////////////////////////////////////////////////////////////////////////
//
//	Function:  		of_RelativeMonth
//
//	Access:			Public
//
//	Arguments:
//	ad_source		Base date (starting poing).
//	al_month	 		Number of months to increment or decrement the base date by.
//
//	Returns:  		date 
//						The adjusted date.
//						If any argument's value is NULL, function returns NULL.
//						If any argument's value is Invalid, function returns 1900-01-01.
//
//	Description:  	Given a date, will return the date +/- the number of months passed
//						in the second parameter.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Revision History	
//
//	Version
//	5.0   Initial version
//	5.0.03	Fixed - function would fail under some international date sets
// 7.0 	Removed a loop which determined the last day in month.  The loop was 
//			relying on the of_IsValid(date) function to find an invalid date.  
//			In PB 5.0.03+ a date variable can only contain a Null or a valid date
//			Used an ii_daysinmonth[] array instead.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//	Any distribution of the PowerBuilder Foundation Classes (PFC)
//	source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////

integer li_adjust_months, li_adjust_years
integer li_month, li_year, 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 of_IsValid(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)

// If the date is > than last in month set it to the last day
If li_day > ii_daysinmonth[li_month] Then
	If li_month = 2 and of_isleapyear(date(li_year, 01, 01)) Then
		li_day = 29
	Else
		li_day = ii_daysinmonth[li_month]
	end If
End IF

Return( Date(li_year, li_month, li_day))

end function

     
Name Owner
No Data

     
Name Owner
systemfunctions.date systemfunctions
systemfunctions.day systemfunctions
systemfunctions.isnull systemfunctions
systemfunctions.mod systemfunctions
systemfunctions.month systemfunctions
systemfunctions.setnull systemfunctions
systemfunctions.year systemfunctions
pfc_n_cst_datetime.of_isleapyear pfc_n_cst_datetime
pfc_n_cst_datetime.of_isvalid pfc_n_cst_datetime

     
Full name
No Data

     
Name Scope
No Data