Consequently, I came up with the following simple "addMinutes" function. This function takes a submitted time and a submitted number of minutes to add, and then returns the resulting time. If the new time is past midnight, it returns the time for the next day.

Here is the code:

Code: Select all

`Inputs: RefTime(numeric),RefMinutesToAdd(numeric);`

Vars: vOriginalMinutes(0), vOriginalHours(0);

Vars: vTestMinutes(0);

Vars: vTempMinutes(0), vTempHours(0);

Vars: vNewMinutes(0), vNewHours(0);

vOriginalHours = IntPortion(RefTime/100);

vOriginalMinutes = Mod(RefTime,100);

vTestMinutes = vOriginalMinutes + RefMinutesToAdd;

If vTestMinutes <= 59 Then Begin

vNewMinutes = vTestMinutes;

vNewHours = vOriginalHours;

End;

If vTestMinutes > 59 Then Begin

vTempMinutes = Mod(vTestMinutes,60);

vTempHours = IntPortion(vTestMinutes/60);

vNewMinutes = vTempMinutes;

If vNewMinutes > 59 Then Begin

vNewMinutes = vNewMinutes - 60;

vTempHours = vTempHours + 1;

End;

vNewHours = vOriginalHours + vTempHours;

If vNewHours > 23 Then vNewHours = vNewHours - 24;

End;

AddMinutes = (vNewHours * 100) + vNewMinutes;

I've tested it on a limited basis and it seems to work fine. Maybe there is an easier way to do this but I don't know what it is. Feel free to play with it and let me know if you have any questions, ideas, bug reports or suggestions.