KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Store Date as ISO format String in Object
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: May 22, 2019

Date stored in object used to be converted to ISO formatted string prior to V17. Since V17, 4D date type is supported in object and becomes the default type for date data. A date value can be assigned to any object property and retrieved as data value:

C_OBJECT($timeObject)
C_DATE($date)
$timeObject:=New object("date";Current date)
$date:=$timeObject.date //Value: 05/14/19


Storing date as ISO format string now becomes an optional database parameter that can be set using SET DATABASE PARAMETER command. This parameter has three possible values: String type without time zone (0), String type with time zone (1), and the default value: Date type (2).

It is worth noting that when an object containing date is returned as JSON to frontend such as web and mobile, 4D converts date value to string in the output:

C_OBJECT($timeObject)
$timeObject:=New object("date";Current date)
$0:=$timeObject
//{
// "result": {
// "date": "2019-05-14T00:00:00.000Z"
// }
//}


The first two options to store date as ISO string format in object are useful in this use case because it converts date to ISO strings beforehand. In addition, the String type with time zone includes time zone value in converted string, for example:

SET DATABASE PARAMETER (Dates inside objects;String type with time zone)
C_OBJECT($timeObject)
$timeObject:=New object("date";Current date)
$0:=$timeObject
//{
// "result": {
// "date": "2019-05-14T07:00:00.000Z"
// }
//}


The 07:00:00.000Z indicates the time zone is in GMT-7, which is the time zone of Pacific Standard Time during Daylight Savings Time.

Utilizing this information, the frontend will be able to convert date across different time zones. This is especially helpful to public web and mobile applications that has international users.

The scope of Dates inside objects parameter is current process. Each process that needs to save date inside object as string will need to call SET DATABASE PARAMETER command separately.