Formats a date using a given locale.

Text = SRP_Date("Format", Date, Format = "Short", Locale = "")

Returns

Formatted text.

Parameters

ParameterDescription
DateA date in OI internal format. (REQUIRED)
FormatA custom or predefined format. (OPTIONAL)
LocaleA locale for culture specific formatting. (OPTIONAL)

Remarks

The "Format" service converts an OI date into human readable text, much like OConv. Unlike OConv, however, this service supports infinite formatting options and localization.

Auto Format

You can set Format to either "Short" or "Long". In either case, the Locale will determine the format. Here are some examples, all formatting the date January 14, 2020:

LocaleShort FormatLong Format
en-US1/14/2020Tuesday, January 14, 2020
es-ES14/01/2020martes, 14 de enero de 2020
fr-FR14/01/2020mardi 14 janvier 2020

If you omit Format or set it to "", then "Short" will be used.

Custom Format

You customize the format using a special syntax. You can use any characters in the Format, but 'Y', 'y', 'M', 'm', 'D', and 'd' are reserved characters. Any other character is treated as a literal and is displayed as is. Thus, you may use literal characters in your format to prefix or suffix the date as you choose. If you need to use any reserved characters literally, then surround your literal text in single or double quotes. If you need to display quotes, place two of them side by side. The reserved characters are interpreted as follows:

Character(s)DisplaysExample using 1/14/2020Example using es-ES
YY2-digit year2020
YYYYYear20202020
MMonth11
MM2-digit Month0101
MMMAbbreviated month nameJanene.
MMMMMonth nameJanuaryenero
MMMMMMonth initialJe
DDay1414
DD2-digit day1414
DDDAbbreviate day of the week nameTuema.
DDDDDay of the weekTuesdaymartes
DDDDDShortest day of the week nameTuM

As you can see in the table above, the Locale still affects the output, but only when your format requests names. months from minutes.

Here are some example date formats, all them for the date January 14, 2020:

Format

en-USes-ESfr-FR
MMMM D, YYYYJanuary 14, 2020enero 14, 2020janvier 14, 2020
DDDD, MMM DD, YYYYSunday, Jan 01, 2006martes, ene. 14, 2020mardi, janv. 14, 2020
M/D/YY1/14/201/14/201/14/20
YYYY-MM-DD2020-01-142020-01-142020-01-14
"Happy New Year! It's" MMMM DD!Happy New Year! It's January 14!Happy New Year! It's enero 14!Happy New Year! It's janvier 14!

Only uppercase letters are used in the examples here, but lowercase are supported as well. However, we recommend using uppercase for dates because SRP_DateTime uses 'M' for months and 'm' for minutes.

Locale

The Locale parameter specifies the specific culture used to help render the final text. Omitting Locale or setting it "" causes the "Format" service to use the user's current Windows locale setting. If, however, you want to specify your own localization, set this parameter to a locale name.

Examples

// Create an OI date
Date = SRP_Date("Encode", 2020, 1, 14)

// Format a date using the default format and the current locale
Text = SRP_Date("Format", Date)

// Format a date using the long format and the current locale
Text = SRP_Date("Format", Date, "Long")

// Format a date using the long format and the Spanish language
Text = SRP_Date("Format", Date, "Long", "es")

// Format a date using a custom format and the Spanish-MEXICAN language
Text = SRP_Date("Format", Date, "MMMM D, YYYY", "es-MX")
  • No labels