Search code examples
lotus-noteslotus-dominolotus-formula

Lotus Notes: Calculating Hours including the next day


I am calculating the sum of hours between two fields: TimeIn and TimeOut, the result will display on my computed for display field hoursWorked. The problem is, when I input 15:00 on the first field and 01:00 on the second field, it doesn't display anything. I tried putting a @If to execute two calculations that if TimeOut is less than TimeIn it will use the first action, but still nothing. Here's my code:

thours:=@If(@IsNull(TimeIn) | @IsNull(TimeOut)=""; @Return(""); "" );
seconds := @If(TimeOut < Timein;(24 + TimeIn) - TimeOut; TimeIn - TimeOut);
hours := @Integer(seconds/3600);
minutes := @Integer(@Modulo(seconds;3600)/60);
output := @Right("00" + @Text(hours); 2) + ":" + @Right("00" + @Text(minutes); 2);
@TextToTime(output)

Solution

  • Calculate the seconds this way:

    seconds := TimeOut - TimeIn;
    seconds := @If(seconds < 0; seconds + 24*3600; seconds);
    

    Whenever TimeOut is smaller then TimeIn it is assumed that the time frame goes from one day to the next day.

    Examples:

    TimeIn   TimeOut   hoursWorked
    15:00    01:00     10:00
    15:00    14:45     23:45
    15:00    17:00     02:00