4D v13.4

Time Operators

Home

 
4D v13.4
Time Operators

Time Operators  


 

 

An expression that uses a time operator returns a time or a number, depending on the operation. The following table shows the time operators:

OperationSyntaxReturnsExpressionValue
AdditionTime + TimeTime?02:03:04? + ?01:02:03??03:05:07?
SubtractionTime – TimeTime?02:03:04? – ?01:02:03??01:01:01?
AdditionTime + NumberNumber?02:03:04? + 657449
SubtractionTime – NumberNumber?02:03:04? – 657319
MultiplicationTime * NumberNumber?02:03:04? * 214768
DivisionTime / NumberNumber?02:03:04? / 23692
Longint divisionTime \ NumberNumber?02:03:04? \ 23692
ModuloTime % TimeTime?20:10:00? % ?04:20:00??02:50:00?
ModuloTime % NumberNumber?02:03:04? % 20

To obtain a time expression from an expression that combines a time expression with a number, use the commands Time and Time string.

Example:

  ` The following line assigns to $vlSeconds the number of seconds that will be elapsed
  ` between midnight and one hour from now
 $vlSeconds:=Current time+3600
 
  ` The following line assigns to $vHSoon the time it will be in one hour
 $vhSoon:=Time(Time string(Current time+3600))

The second line could be written in a simpler way:

  ` The following line assigns to $vHSoon the time it will be in one hour
 $vhSoon:=Current time+?01:00:00?

However, while developing your application, you may encounter situations where a delay, expressed in seconds and added to a time value, is only available to you as a numeric value.
In this case, use the next tip.

Some situations may require you to convert a time expression into a numeric expression.
For example, you open a document using Open document, which returns a Document Reference (DocRef) that is formally a time expression. Later, you want to pass that DocRef to a 4D Extension routine that expects a numeric value as document reference. In such a case, use the addition with 0 (zero) to get a numeric value from the time value, but without changing its value.

Example:

  ` Select and open a document
 $vhDocRef:=Open document("")
 If(OK=1)
  ` Pass the DocRef time expression as a numeric expresssion to a 4D Extension routine
    DO SOMETHING SPECIAL(0+$vhDocRef)
 End if

The Modulo operator can be used, more specifically, to add times that take the 24-hour format into account:

 $t1:=?23:00:00? // It is 23:00 p.m.
  // We want to add 2 and a half hours
 $t2:=$t1 +?02:30:00? // With a simple addition, $t2 is ?25:30:00?
 $t2:=($t1 +?02:30:00?)%?24:00:00? // $t2 is ?01:30:00? and it is 1:30 a.m. the next morning

 
PROPERTIES 

Product: 4D
Theme: Operators

 
SEE ALSO 

Bitwise Operators
Comparison Operators
Date Operators
Logical Operators
Numeric Operators
Operators
Picture Operators
String Operators