Tech Tip: Simple ways to convert time data type to seconds
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: January 30, 2019
When trying to convert time type into seconds, generally one misleading approach would be to use the Num() command. However this command does not allow time types as an argument and would lead to an incompatible argument error.
C_TIME($currTime) $currTime:=Current time $sec1:=Num($currTime) // Incorrect |
Instead, you can simply use basic arithmetic (+, -, *, /) against the time data type which will automatically convert it to seconds as shown below.
C_LONGINT($s1;$s2;$s3;$s4) C_TIME($currTime) $currTime:=Current time $s1:=$currTime+0 $s2:=$currTime-0 $s3:=$currTime*1 $s4:=$currTime/1 |
In addition, assigning a time data type to an object property value will also automatically convert to seconds.
C_OBJECT($timeObj) $currTime:=Current time $timeObj:=New object("current_time";$currTime) |