KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Number of seconds between two ISO date timestamps
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: April 13, 2016

The follow code snippet uses the PHP function strtotime and 4D's PHP EXECUTE command to determine the number of seconds between two ISO date timestamps:

C_LONGINT($0)
C_TEXT($1;$2)
C_LONGINT($o1;$o2)
C_BOOLEAN($phpOK)
If (Count parameters=2)
   $phpOK:=PHP Execute("";"strtotime";$o1;$1)
   $phpOK:=PHP Execute("";"strtotime";$o2;$2)
   $0:=$o2-$o1
End if

If the code is saved in a project method named UTIL_SecondsBetweenISOdates it could then be used like this:
$t1:="2014-03-17T19:34:14Z"
$t2:="2016-03-21T14:32:38Z"
Alert(string(UTIL_SecondsBetweenISOdates($t1;$t2)))

See Also: