Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TIME and LTIME

A TIME is a signed 32-bit count of milliseconds, ±24d20h31m23s647ms; an LTIME a signed 64-bit count of nanoseconds, ±292 years. Both may be negative (Ed.3 Table 8: T#-14ms). A TIME literal must be whole milliseconds; an LTIME literal whole nanoseconds.

Adding and subtracting

Exact; a result outside the type wraps and is flagged OVERFLOW, as an integer’s does. So is a negation, -t: the lowest TIME has no positive.

ExpressionTypeResultFlagNote
T#1s + T#500msTIMET#1s500ms—
T#1s - T#1500msTIMET#-500ms—negative durations exist
T#24d20h31m23s647ms + T#1msTIMET#-24d20h31m23s648msflag OVERFLOW
LTIME#1s + LTIME#1nsLTIMELTIME#1s1ns—
-(T#1s500ms)TIMET#-1s500ms—a negation
-(LTIME#2ns)LTIMELTIME#-2ns—
-(T#-24d20h31m23s648ms)TIMET#-24d20h31m23s648msflag OVERFLOWits negation is past the top

TIME and LTIME, one made the other

A TIME becomes an LTIME without a conversion function (Ed.3 Figure 11), exactly. LTIME_TO_TIME drops what is below a millisecond, rounding down, unflagged; an LTIME beyond TIME gives T#0s, flagged CONVERSION (decided 2026-11-08, florin; LDATE, LTOD and LDT).

ExpressionTypeResultFlagNote
T#-1500ms + LTIME#0sLTIMELTIME#-1500ms—widened
LTIME_TO_TIME(LTIME#1ms999us)TIMET#1ms—rounding down
LTIME_TO_TIME(LTIME#-1500us)TIMET#-2ms—down, not toward zero
LTIME_TO_TIME(LTIME#25d)TIMET#0sflag CONVERSIONbeyond TIME

Times and divided by a number

Ed.3 Table 30 multiplies and divides a duration by any number (MUL_TIME, DIV_TIME, or * and /); a number may also stand first in *. How the result becomes whole milliseconds is the implementer’s (Implementer choices):

  • by an integer, exact; an overflow wraps and is flagged; a division goes toward zero, as DINT’s;
  • by a REAL or LREAL, computed in LREAL and rounded to whole milliseconds, half to even, as REAL_TO_DINT rounds; a result outside TIME, or infinite, or NaN is flagged CONVERSION and the statement left undone, as any real made an integer;
  • by zero, 0 or 0.0, a fault.

Panasonic and PLCnext round the factor to a whole number first, so on them T#1s * 2.5 is 2 or 3 seconds; in iecf it is 2.5.

ExpressionTypeResultFlagNote
T#1s * 3TIMET#3s—
3 * T#1sTIMET#3s—either order
T#10s / 3TIMET#3s333ms—toward zero
T#-7ms / 2TIMET#-3ms—toward zero
T#1s * REAL#2.5TIMET#2s500ms—
T#3ms * REAL#1.5TIMET#4ms—4.5: half to even
T#5ms * REAL#1.5TIMET#8ms—7.5: half to even
T#1s / REAL#3.0TIMET#333ms—333.33
T#1s * REAL#1.0E10TIMEunchangedflag CONVERSIONbeyond TIME: left undone
T#1s / 0TIME—fault DIVISION_BY_ZERO
T#1s / REAL#0.0TIME—fault DIVISION_BY_ZERO
T#24d * 2TIMET#-1d17h2m47s296msflag OVERFLOWwrapped
MUL_TIME(T#2s, 2)TIMET#4s—
DIV_TIME(T#1m, 4)TIMET#15s—
LTIME#1us * 1500LTIMELTIME#1ms500us—

matiec holds nanoseconds in a TIME, so its T#10s / 3 is 3.333333333 s; iecf’s TIME counts milliseconds, as every vendor’s does.