You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Formats a datetime using a given locale.

Text = SRP_DateTime("Format", Datetime, Format = "Short", Locale = "")

Returns

Formatted text.

Parameters

ParameterDescription
DatetimeA datetime 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 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:

LocaleShort FormatLong Format
en-US1/14/2020 3:07 PMTuesday, January 14, 2020 3:07:43 PM
es-ES14/01/2020 15:07martes, 14 de enero de 2020 15:07:43
fr-FR14/01/2020 15:07mardi 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)DisplaysExample using 1/14/2020 3:07:43pmExample 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
hHour1515
hh2-digit hour1515
mMinute77
mm2-digit minute0707
sSecond4343
ss2-digit second4343
aa/ppp
aaam/pmpmpm
aaaa.m./p.m.p.m.p.m.
AA/PPP
AAAM/PMPMPM
AAAA.M./P.M.P.M.P.M.
tAbbreviated cultural am/pmpp
ttCultural am/pmPMp

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-USes-ESfr-FR
MMMM D, YYYY, h:mm aaaJanuary 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:ssttTuesday, Jan 14, 2020 at 3:17:43PM
martes, ene. 14, 2020 at 3:17:43pmardi, janv. 14, 2020 at 3:17:43PM
YYYY-MM-DD hh:mm:ss2020-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 locale setting. If, however, you want to specify your own localization, set this parameter to a locale name. Locale names have a complex syntax that allow you to specify all manner of aspects, but in 99.99% of cases, you'll use the format "language-REGION". Here, language is a lowercase ISO 639-1 language code. REGION specifies an uppercase ISO 3166-1 country/region identifier. The region is optional. For example, the locale name for English is "en", the locale name for English (United States) is "en-US", and the locale name for Divehi (Maldives) is "dv-MV".

Here is a chart for the 200 most common languages and regions:

Language CodeDescription
afAfrikaans
af-ZAAfrikaans - South Africa
arArabic
ar-AEArabic - United Arab Emirates
ar-BHArabic - Bahrain
ar-DZArabic - Algeria
ar-EGArabic - Egypt
ar-IQArabic - Iraq
ar-JOArabic - Jordan
ar-KWArabic - Kuwait
ar-LBArabic - Lebanon
ar-LYArabic - Libya
ar-MAArabic - Morocco
ar-OMArabic - Oman
ar-QAArabic - Qatar
ar-SAArabic - Saudi Arabia
ar-SYArabic - Syria
ar-TNArabic - Tunisia
ar-YEArabic - Yemen
azAzeri
az-AZCyrl Azeri (Cyrillic) - Azerbaijan
az-AZ-LatnAzeri (Latin) - Azerbaijan
beBelarusian
be-BYBelarusian - Belarus
bgBulgarian
bg-BGBulgarian - Bulgaria
caCatalan
ca-ESCatalan - Catalan
csCzech
cs-CZCzech - Czech Republic
daDanish
da-DKDanish - Denmark
deGerman
de-ATGerman - Austria
de-CHGerman - Switzerland
de-DEGerman - Germany
de-LIGerman - Liechtenstein
de-LUGerman - Luxembourg
divDhivehi
div-MVDhivehi - Maldives
elGreek
el-GRGreek - Greece
enEnglish
en-AUEnglish - Australia
en-BZEnglish - Belize
en-CAEnglish - Canada
en-CBEnglish - Caribbean
en-GBEnglish - United Kingdom
en-IEEnglish - Ireland
en-JMEnglish - Jamaica
en-NZEnglish - New Zealand
en-PHEnglish - Philippines
en-TTEnglish - Trinidad and Tobago
en-USEnglish - United States
en-ZA `English - South Africa
en-ZWEnglish - Zimbabwe
esSpanish
es-ARSpanish - Argentina
es-BOSpanish - Bolivia
es-CLeSpanish - Chile
es-COSpanish - Colombia
es-CRSpanish - Costa Rica
es-DOSpanish - Dominican Republic
es-ECSpanish - Ecuador
es-ESSpanish - Spain
es-GTSpanish - Guatemala
es-HNSpanish - Honduras
es-MXSpanish - Mexico
es-NI SpanishSpanish - Nicaragua
es-PASpanish - Panama
es-PESpanish - Peru
es-PRSpanish - Puerto Rico
es-PYSpanish - Paraguay
es-SVSpanish - El Salvador
es-UYSpanish - Uruguay
es-VESpanish - Venezuela
etEstonian
et-EEEstonian - Estonia
euBasque
eu-ESBasque - Basque
faFarsi
fa-IRFarsi - Iran
fiFinnish
fi-FIFinnish - Finland
foFaroese
fo-FOFaroese - Faroe Islands
frFrench
fr-BEFrench - Belgium
fr-CAFrench - Canada
fr-CHFrench - Switzerland
fr-FRFrench - France
fr-LUFrench - Luxembourg
fr-MCFrench - Monaco
glGalician
gl-ESGalician - Galician
guGujarati
gu-INGujarati - India
heHebrew
he-ILHebrew - Israel
hiHindi
hi-INHindi - India
hrCroatian
hr-HRCroatian - Croatia
huHungarian
hu-HUHungarian - Hungary
hyArmenian
hy-AMArmenian - Armenia
idIndonesian
id-IDIndonesian - Indonesia
isIcelandic
is-ISIcelandic - Iceland
itItalian
it-CH ItalianItalian - Switzerland
it-ITItalian - Italy
jaJapanese
ja-JPJapanese - Japan
kaGeorgian
ka-GEGeorgian - Georgia
kkKazakh
kk-KZKazakh - Kazakhstan
knKannada
kn-INKannada - India
koKorean
kokKonkani
kok-INKonkani - India
ko-KRKorean - Korea
kyKyrgyz
ky-KGKyrgyz - Kyrgyzstan
ltLithuanian
lt-LTLithuanian - Lithuania
lvLatvian
lv-LVLatvian - Latvia
mkMacedonian
mk-MKMacedonian - Former Yugoslav Republic of Macedonia
mnMongolian
mn-MNMongolian - Mongolia
mrMarathi
mr-INMarathi - India
msMalay
ms-BNMalay - Brunei
ms-MYMalay - Malaysia
nb-NONorwegian (Bokm?l) - Norway
nlDutch
nl-BEDutch - Belgium
nl-NLDutch - The Netherlands
nn-NONorwegian (Nynorsk) - Norway
noNorwegian
paPunjabi
pa-INPunjabi - India
plPolish
pl-PLPolish - Poland
ptPortuguese
pt-BRPortuguese - Brazil
pt-PTPortuguese - Portugal
roRomanian
ro-RORomanian - Romania
ruRussian
ru-RURussian - Russia
saSanskrit
sa-INSanskrit - India
skSlovak
sk-SKSlovak - Slovakia
slSlovenian
sl-SISlovenian - Slovenia
sqAlbanian
sq-ALAlbanian - Albania
sr-SP-CyrlSerbian (Cyrillic) - Serbia
sr-SP-LatnSerbian (Latin) - Serbia
svSwedish
sv-FISwedish - Finland
sv-SESwedish - Sweden
swSwahili
sw-KESwahili - Kenya
syrSyriac
syr-SYSyriac - Syria
taTamil
ta-INTamil - India
teTelugu
te-INTelugu - India
thThai
th-THThai - Thailand
trTurkish
tr-TRTurkish - Turkey
ttTatar
tt-RUTatar - Russia
ukUkrainian
uk-UAUkrainian - Ukraine
urUrdu
ur-PKUrdu - Pakistan
uzUzbek
uz-UZ-CyrlUzbek (Cyrillic) - Uzbekistan
uz-UZ-LatnUzbek (Latin) - Uzbekistan
viVietnamese
zh-CHTChinese (Traditional)
zh-CHSChinese (Simplified)
zh-CNChinese - China
zh-HKChinese - Hong Kong SAR
zh-MOChinese - Macao SAR
zh-SGChinese - Singapore
zh-TWChinese - Taiwan

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")
  • No labels