Formats a datetime using a given locale.
Text = SRP_DateTime("Format", Datetime, Format = "Short", Locale = "")
Returns
Formatted text.
Parameters
Parameter | Description |
---|---|
Datetime | A datetime in OI internal format. (REQUIRED) |
Format | A custom or predefined format. (OPTIONAL) |
Locale | A locale for culture specific formatting. (OPTIONAL) |
Remarks
The "Format" service converts an OI datetime 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 datetime January 14, 2020 at 3:07:43pm:
Locale | Short Format | Long Format |
---|---|---|
en-US | 1/14/2020 3:07 PM | Tuesday, January 14, 2020 3:07:43 PM |
es-ES | 14/01/2020 15:07 | martes, 14 de enero de 2020 15:07:43 |
fr-FR | 14/01/2020 15:07 | mardi 14 janvier 2020 15:07:43 |
If you omit Format or set it to "", then "Short" will be used.
Custom Format
You can customize the format using a special syntax. You can use any characters in the Format, but 'Y', 'y', 'M', 'm', 'D', 'd', 'H', 'h', 'S', 's', 'A', 'a', 'T', and 't' 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) | Displays | Example using 1/14/2020 3:07:43pm | Example using es-ES |
---|---|---|---|
YY | 2-digit year | 20 | 20 |
YYYY | Year | 2020 | 2020 |
M | Month | 1 | 1 |
MM | 2-digit Month | 01 | 01 |
MMM | Abbreviated month name | Jan | ene. |
MMMM | Month name | January | enero |
MMMMM | Month initial | J | e |
D | Day | 14 | 14 |
DD | 2-digit day | 14 | 14 |
DDD | Abbreviate day of the week name | Tue | ma. |
DDDD | Day of the week | Tuesday | martes |
DDDDD | Shortest day of the week name | Tu | M |
h | Hour | 15 | 15 |
hh | 2-digit hour | 15 | 15 |
m | Minute | 7 | 7 |
mm | 2-digit minute | 07 | 07 |
s | Second | 43 | 43 |
ss | 2-digit second | 43 | 43 |
a | a/p | p | p |
aa | am/pm | pm | pm |
aaa | a.m./p.m. | p.m. | p.m. |
A | A/P | P | P |
AA | AM/PM | PM | PM |
AAA | A.M./P.M. | P.M. | P.M. |
t | Abbreviated cultural am/pm | p | p |
tt | Cultural am/pm | PM | p |
As you can see in the table above, the Locale still affects the output, but only when your format requires it.
Here are some example datetime formats, all them for the date January 14, 2020 at 3:07:43pm:
Format | en-US | es-ES | fr-FR |
---|---|---|---|
MMMM D, YYYY, h:mm aaa | January 14, 2020, 3:17 p.m. | enero 14, 2020, 3:17 p.m. | janvier 14, 2020, 3:17 p.m. |
DDDD, MMM DD, YYYY 'at' h:mm:sstt | Tuesday, Jan 14, 2020 at 3:17:43PM | martes, ene. 14, 2020 at 3:17:43p | mardi, janv. 14, 2020 at 3:17:43PM |
YYYY-MM-DD hh:mm:ss | 2020-01-14 15:17:43 | 2020-01-14 15:17:43 | 2020-01-14 15:17:43 |
You can use uppercase or lowercase for all format codes except for months and minutes. 'M' must be used for months and 'm' must be used 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 datetime Datetime = SRP_DateTime("Encode", 2020, 1, 14, 3, 7, 43) // Format a datetime using the default format and the current locale Text = SRP_DateTime("Format", Datetime) // Format a datetime using the long format and the current locale Text = SRP_DateTime("Format", Datetime, "Long") // Format a datetime using the long format and the Spanish language Text = SRP_DateTime("Format", Datetime, "Long", "es") // Format a datetime using a custom format and the Spanish-MEXICAN language Text = SRP_DateTime("Format", Datetime, "MMMM D, YYYY 'at' h:mm:ss tt", "es-MX")