Tech Tip: Utility method to return a complete ISO date-time-string
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: October 2, 2013
When using the String command with the ISO Date constant a string like this is produced; "2013-09-11T00:00:00", which is an incomplete ISO date-time string. The utility below will return a complete ISO date-time string like this "2013-09-11T15:55:44."
The utility can take two optional parameters, Date and Time. If the no parameters are passed the utility uses Current date and Current time by default.
If (True) If (False) Begin SQL /* Name: UTIL_ISO_DateTimeString({ $Date_D {; $Time_H }}) Path: UTIL_ISO_DateTimeString Purpose: Return a full ISO Date + Time string $0 - string 20 - The ISO formated date-time string $1 - Date - Optional date $2 - Time - Optional time */ End SQL End if C_TEXT($MethodName_T) $MethodName_T:=Current method name //===================== Declare Variables ================================== //method_parameters_declarations C_STRING(21;$0;$DTStr_A20) C_DATE($Date_D;$1) C_TIME($Time_H;$2) //-------------------------------------------------------------------------------- //method_wide_constants_declarations //-------------------------------------------------------------------------------- //local_variable_declarations C_LONGINT($Ndx;$SOA;$RIS;$Params_L) End if //====================== Initialize and Setup ================================ $Date_D:=Current date $Time_H:=Current time $Params_L:=Count parameters If ($Params_L>0) $Date_D:=$1 If ($Params_L>1) $Time_H:=$2 End if End if //======================== Method Actions ================================== $DTStr_A20:=String($Date_D;ISO date) $DTStr_A20:=Substring($DTStr_A20;1;Position("T";$DTStr_A20))+String($Time_H;HH MM SS) //======================== Clean up and Exit ================================= $0:=$DTStr_A20 |
Commented by Tim Penner on March 1, 2017 at 12:03 PM
Starting with v16R2 this can be replaced with a call to the TIMESTAMP command:
http://livedoc.4d.com/4Dv16-R2/help/Command/en/page1445.html