People Code to add duration to time field.
Example:
Here START_TIME, END_TIME is time field and DURATION is number field.
InPut: StartTime(START_TIME ) = 8:00AM and Duration(DURATION ) = 12
OutPut: EndTime(END_TIME) = 8:00PM
Sample Code:
Declare Function Return_DateTime_value PeopleCode TIME_TBL.START_TIME FieldFormula;
Declare Function Return_Hour_Min_Part PeopleCode TIME_TBL.START_TIME FieldFormula;
Local datetime &TIME_VALUE;
Local integer &MINUTES;
&DUR_VALUE = TIME_TBL.DURATION.Value;
&StartTime = TIME_TBL.START_TIME.Value;
Return_DateTime_value(&StartTime, &DUR_VALUE, &TIME_VALUE);
Return_Hour_Min_Part(&DUR_VALUE, &HOUR_PART, &MINUTES);
TIME_TBL.END_TIME.Value = TimePart(AddToDateTime(&TIME_VALUE, 0, 0, 0, &HOUR_PART, &MINUTES, 0));
Defining Functions:
Function Return_DateTime_value(&StartTime, &DUR_VALUE, &TIME_VALUE As datetime);
Local date &RefDate;
&RefDate = Date3(2000, 1, 1);
&TIME_VALUE = &RefDate + &StartTime;
End-Function;
Function Return_Hour_Min_Part(&DUR_VALUE, &iHour, &iMinutes As integer)
&temp = String(&DUR_VALUE);
&iHour = Value(Substring(&temp, 1, 2));
&iPos = (Find(".", &temp));
If &iPos > 0 Then
&sMinutes = Substring(&temp, &iPos + 1, 2);
If Substring(&sMinutes, 1, 1) = "0" Or
Len(&sMinutes) > 1 Then
&iMinutes = Value(&sMinutes);
&iMinutes = ((&iMinutes / 100) * 60)
Else
&iMinutes = Value(&sMinutes);
&iMinutes = ((&iMinutes / 10) * 60)
End-If;
Else
&iMinutes = 0;
End-If;
End-Function;
0 comments:
Post a Comment