Tech Tip: Date Values In Objects
PRODUCT: 4D | VERSION: 16 R, 17 | PLATFORM: Mac & Win
Published On: September 14, 2018
Objects in 4D are based off of the standards of JSON formatted data, however 4D contains additional features that will allow the use of objects to be mroe streamlined with their typical intended uses.
One of the features that 4D Objects have is the behavior when working with dates that was introduced in v16R4. A date value is not a standard data type that the JSON format contains, instead it can typically be contained as a string or somehow as a numeric value.
Note: More on JSON value data types: https://www.json.org/
Starting with v16R4, when a 4D Date is inserted into an Object, the value is stored as a string in ISO date format. This also occurs with a date is inserted into the object as a string in the format of "YYYY-MM-DD".
Example:
C_OBJECT($varObj) OB SET($varObj;"date1";!20/10/2018!) OB SET($varObj;"date2";"2018-10-20") |
$varObj will contain:
{
date1 : "2018-10-20T00:00:00.000Z",
date2 : "2018-10-20T00:00:00.000Z"
}
However, in the cases that the ISO date format is not desired, the date should instead be converted into a string in any format other than the two above. This can be done using the STRING command on a 4D Date which can be formatted in different standards.
Example:
C_OBJECT($varObj) C_TEXT($strDate) $strDate:=STRING(!20/10/2018!) //$strDate is set to "10/20/18" OB SET($varObj;"date";$strDate) |
$varObj will contain:
{
date : "10/20/18"
}
Related:
Date Data Types in Objects