Dates inside objects!

Objects are great! Their flexibility, combined with speed and elegance, make them a first choice for most developers. Using dates inside objects is now easier and more intuitive. From now on, dates can be set as datesand not strings inside objects!

How does it work?

In order to use dates inside objects, just check the compatibility setting, “Use date type instead of ISO date format in objects”, in the Database Settings.

Once this is done, OB SET and OB Get work without requiring the is date constant.

OB SET ($myObject;"myDate";$date)
$date:=OB Get ($myObject;"myDate")

Object Notation also works! Take a look:


Stringify and Parse

Compatibility is maintained

Prior to 4D v16 R6, when calling the JSON Stringify command, objects containing dates were systematically “stringified” according to the ISO 8601 normalization in the following format “YYYY-MM-DDThhmmss.sssZ” . The reverse operation, JSON Parse, did not interpret this format by default, and therefore produced a string.

What’s new?

If the compatibility option in the Database Settings is checked, dates will simply be formatted as “YYYY-MM-DD” (still following the ISO 8601 standard) when calling the JSON stringify command. When using JSON Parse, this string will then be set as a date (and not as a string) inside the object!

Change mode dynamically

If needed, this default setting can be changed by programming with the SET DATABASE PARAMETER command and the Dates inside object selector.

Reminder: SET DATABASE PARAMETER(Dates inside object;option) is local to the current process.

The three possible values for this option are now:

  • String type without time zone  (previously known as ignore local time zone)
  • String type with time zone  (previously known as take time zone into account)
  • Date type (new!)

As a result, when you import JSON data into 4D, you now have a way to dynamically change the format for dates.

Roland Lannuzel
• Product Owner & 4D Expert •After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.