date2Str Function

Converts a date into a text string.

MorphX allocates valid values to the formatting parameters if the specified values are not valid.


str date2Str(
    date date,
    int sequence,
    int day,
    int separator1,
    int month,
    int separator2,
    int year)

Parameter

Description

date

The date to be converted.

sequence

The sequence for the components of the date (day, month, year).

Day is shown by 1, month by 2, and year by 3.

For example:

  • 123: gives a sequence of: day, month, year.

  • 312: gives a sequence of: year, day, month

day

The format for the day component of the date.

Possible formats:

  • Can be expressed as one or two digits, as required

  • Always expressed as two digits

separator1

The separator to use between the first two components of the date.

Possible values:

  • a " " (space)

  • a "." (period)

  • a "-" (hyphen)

  • a "/" (forward slash)

month

The format for the month.

Possible formats:

  • Can be expressed as one or two digits, as required

  • Expressed as two digits

  • Expressed as three characters

  • Expressed by its entire name

separator2

The separator to use between the last two elements of the date.

Possible values:

  • a " " (space)

  • a "." (period)

  • a "-" (hyphen)

  • a "/" (forward slash)

year

The format for the year.

Possible formats:

  • Expressed as two digits

  • Expressed as four digits

NoteNote

To use the date format that the user specified in Regional Settings, use strFmt or date2Str with -1 in all the formatting parameters. When the regional settings control the date format, the settings can change from user to user.


A string that represents the specified date.

The following example prints today's date in the format day/month/year, with 2 digits for each of the values.

static void date2StrExample(Args _arg)
{
    date d = today();
    str s;
    ;
    s = date2Str(d, 123, 2, -1, 2, -1, 2);
    print "Today's date is " + s;
    pause;
} 

Community Additions

ADD
Show: