KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Creating Custom Time and Date Formats
PRODUCT: 4D | VERSION: 20 R4 | PLATFORM: Mac & Win
Published On: December 2, 2024

A developer may find that they want their times or dates to show up a specific way that is not one of the preset times or dates. Custom time and date formats have been introduced as of 4D v20 R4. A full list of the formatting for time and date formats can be found on the documentation, however below are some examples of what can be done with this feature.

Developers may change the format of a time or date in a listbox. To do so, the option "Custom" must be selected from the property list. The following pattern "Y, MM/dd" makes the listbox entries show up like the examples on the lefthand side of the image. This may also be done with OBJECT SET FORMAT.



Custom date and time formats may also be put in programmatically. These values go in a string just the same as when input into the property list. Notably if the developer wants to add normal letters to the format, they can add them in single quotes and they will be treated as a normal string, not parsed for the date format.

$format:="'The current time is' hh:mmb 'on' EEEE, LLLL dd y"

ALERT(String(Current date; $format; Current time))