4D v14.3Time Operators |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
Time Operators
|
Operation | Syntax | Returns | Expression | Value |
Addition | Time + Time | Time | ?02:03:04? + ?01:02:03? | ?03:05:07? |
Subtraction | Time – Time | Time | ?02:03:04? – ?01:02:03? | ?01:01:01? |
Addition | Time + Number | Number | ?02:03:04? + 65 | 7449 |
Subtraction | Time – Number | Number | ?02:03:04? – 65 | 7319 |
Multiplication | Time * Number | Number | ?02:03:04? * 2 | 14768 |
Division | Time / Number | Number | ?02:03:04? / 2 | 3692 |
Longint division | Time \ Number | Number | ?02:03:04? \ 2 | 3692 |
Modulo | Time % Time | Time | ?20:10:00? % ?04:20:00? | ?02:50:00? |
Modulo | Time % Number | Number | ?02:03:04? % 2 | 0 |
To obtain a time expression from an expression that combines a time expression with a number, use the commands Time and Time string.
You can combine expressions of the time and number types using the Time or Current time functions. For example:
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(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?
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
Product: 4D
Theme: Operators
Bitwise Operators
Comparison Operators
Date Operators
Logical Operators
Numeric Operators
Operators
Picture Operators
String Operators
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)
Inherited from : Time Operators ( 4D v12.4)