Date Primitive Type Examples

You can create a primitive method in type Date to return a string containing the short date in dd-MM-yyyy format, as follows.

testShortDate1(): String;
begin
    return day.String & "-" & month.String & "-" & year.String;
end;

In this example, the day, month, and year values are methods of the Date primitive type. However, the following example shows a more-direct method of returning the date in a short format; that is, the format method enables you to format dates to meet your requirements.

testShortDate2(): String;
vars
    date : Date;
begin
    return date.format("dd-MM-yyyy");
end;

The month is denoted by uppercase letters (that is, MM) to differentiate it from minutes (that is, mm).

You can use the defineLongDateFormat or defineShortDateFormat method of the DateFormat class if you want to create your own transient format objects and define a long or short date format that dynamically overrides the appropriate format for the locale at run time. (For details, see Chapter 1 of the JADE Encyclopaedia of Classes.)

If an attempt is made to format an invalid date, "*invalid*" is returned.

The following example shows the use of the Date primitive type.

daysToXmas(): Integer;     // valid only before xmas day in a specified year
vars
    xmasday, today : Date;
begin
    xmasday.setDate(25, 12, today.year);
    return xmasday - today;
end;