Formatting DATE values

Date values must be formatted when converted to strings.

When does DATE formatting take place?

Date formatting occurs when converting a DATE to a string with the USING operator, for example in a LET, DISPLAY or PRINT instruction, and when displaying date values in form fields defined with the FORMAT attribute.

This example formats a DATE value with the USING operator:

MAIN
  DEFINE d DATE
  LET d = MDY(12,24,2014)
  DISPLAY d USING "mmm ddd yyyy"
END MAIN
This code example produces the following output:
Dec Wed 2014
Default formatting occurs when USING or FORMAT are not used, and a date value has to be converted to a character string, for example when passing a DATE to a function expecting a VARCHAR(n). Default date formatting is based on the date format defined with the DBDATE environment variable. For more details about default formatting, see Data type conversion reference.

This topic describes the syntax of the format-string in the USING "format-string" operator and FORMAT = "format-string" form field attribute.

Formatting symbols for DATE values

When formatting DATE values, the format-string of the USING operator or FORMAT attribute consists of a set of place holders that represent date parts as described in the following table:

Table 1. Format-string symbols for DATE values
Placeholder Description
dd Day of the month as a 2-digit integer.
ddd Three-letter English-language abbreviation of the day of the week. For example: Mon, Tue.
mm Month as a 2-digit integer.
mmm Three-letter English-language abbreviation of the month. For example: Jan, Feb.
yy Year, as a 2-digits integer representing the 2 trailing digits.
yyy Year as a 3-digit number (Ming Guo format only)
yyyy Year as a 4-digit number.
c1 Ming Guo format modifier, see Using the Ming Guo date format.

Any character different from the date-formatting placeholders is interpreted as a literal and will appear as-is in the resulting string.

The calendar used for date formatting is the Gregorian calendar. The c1 placeholder is a formatting symbol used to adapt the date to the Ming Guo calendar.

Table 2. Date formatting examples
Format String Date value Result string
dd/mm/yyyy 2011-10-24 24/10/2011
[dd/mm/yy] 2011-10-24 [24/10/11]
[ddd-mmm-yyyy] 0141-10-24 [Tue-Oct-0141]
(ddd.) mmm. dd, yyyy 1999-09-23 (Thu.) Sep. 23, 1999