Calculating a Time Span Across Midnight Scenario: Employees working third shift at a manufacturing plant start work at 11:30 p.m. and end their workday at 7:45 a.m. the following morning. Subtracting their starting time from their ending time produces an incorrect value. For example, a starting time of 11:30 p.m. and an ending time of 7:45 a.m. produces the incorrect value 15:45. With the formula below, Superbase calculates differently depending on whether or not the starting time is greater than the ending time. File definition: Filename: TIME24HR StartTime hh:mm am EndTime hh:mm am TimeDifference CLC RDO hh:mm Sample record: StartTime 11:00 pm EndTime 7:00 am TimeDifference 8:00 {Calculated result*} *TimeDifference read-only calculation formula IF ( EndTime.TIME24HR < StartTime.TIME24HR , ( 86400000 - ( StartTime.TIME24HR - EndTime.TIME24HR ) ) , EndTime.TIME24HR - StartTime.TIME24HR ) Formula explanation If the EndTime is less than the StartTime then subtract the StartTime from the EndTime and subtract that difference from 86400000, otherwise subtract the StartTime from the EndTime. The value 86400000 is the number of thousandths of a second in 24 hours (one minute is 60,000 thousandths of a second.) Manual references Designing Files, pg. 2-5, "Modifying a file definition" Designing Files, pg. 5-15, "Working with time display formats" Designing Files, pg. 6-1, "Using formulas" SBL Reference, pg. 3-6, "Date and time" SBL Reference, pg. 4-201, "IF" SBL Reference, pg. 4-457, "TIMEVAL" Program: Superbase Versions: 2.0 Date: March 29, 1994 D Date: