timedifference(

timedifference(STARTTIME

, ENDTIME

)
The** timedifference( **function calculates the difference between two times. It works correctly even if the interval between the two times crosses over midnight.

**Parameters**

This function has two parameters:

** starttime** – is a number (number of seconds) representing the starting point of the time interval.

** endtime** – is a number (number of seconds) representing the ending point of the time interval.

**Description**

The *timedifference(* function calculates the time interval between two times. It works correctly even if the interval between the two times crosses over midnight. This function returns a time interval between –12 and +12 hours. See also the timeinterval( function, which returns a time interval between 0 and +24 hours.

If the end time is later in the same day as the start time, the result of the function is the same as subtracting the start time from the end time:

`timepattern(timedifference(time("205a"), time("930a")),"hh:mm") ☞ `*7:25*

If the end time is in the next day, the function adjusts for the fact that the interval crosses over midnight:

`timepattern(timeinterval(time("930p"), time("205a")),"hh:mm") ☞ `*4:35*

If the end time is earlier than the start time, a negative value is returned. This is true even if the time interval crosses midnight.

`timepattern(timedifference(time("930a"), time("205a")),"hh:mm") ☞ `*-7:25*
timepattern(timeinterval(time("205a"), time("930p")),"hh:mm") ☞ *-4:35*

Note: The *timeinterval(* function assumes that the interval is no more than 12 hours positive or negative. If you need to compute timeinterval that cross over multiple days you must use SuperDates, which combine both date and time into a single value.

**See Also**

- info("milliseconds") -- returns the number of milliseconds (1/1000th second) since the system started up.
- info("tickcount") -- returns the number of ticks (1/60th second) since the system started up.
- longtimestr( -- converts a number to text in am/pm time format, including seconds.
- now( -- returns the current time (number of seconds since midnight).
- regulartime( -- extracts a regular time (seconds since midnight) from a superdate.
- secsminshours( -- this converts a time (number of seconds) into an approximate text value.
- superdate( -- converts a regular date and a regular time into a superdate.
- superdatepattern( -- converts a number containing a superdate to text, allowing you to specify the patterns for both the date and the time conversion to text.
- superdatesecondsstr( -- converts a number containing a superdate to text, including the seconds.
- superdatestr( -- converts a number containing a superdate (date + time) to text.
- supernow( -- returns the number representing the current date and time as a superdate.
- texttimedifference( -- allows time math to be performed on text values.
- texttimeinterval( -- allows time math to be performed on text values.
- time( -- converts text into a number representing a time.
- time24( -- takes a time and makes sure it falls within a 24 hour period.
- timeinterval( -- calculates the time interval between two times. It works correctly even if the interval between the two times crosses over midnight.
- timepattern( -- converts a number representing a time into text. The function uses a pattern to control how the time is formatted.
- timestr( -- converts a number to text in am/pm time format.

**History**

Version | Status | Notes |

10.0 | No Change | Carried over from Panorama 6.0 |