2022.2

Table Of Contents
String.Thecustompatternmayconsistofpatternletters,separatingsymbolsandquotedtext,for
example:"'at'HH:mm:ssz";see"Dateandtimepatterns"onthefacingpage.Notethattherepetitionof
patternlettersdeterminestheexactpresentation.
timeLong(value)
Formatsatimeaslongstringrepresentation,forexample12:00:00 EDT AM.
value
ADateobject.ADatecancontainadateandtime.
timeMedium(value)
Formatsatimeasmediumstringrepresentation,forexample12:00:00 AM.
value
ADateobject.ADatecancontainadateandtime.
timeShort(value)
Formatsatimeasshortstringrepresentation,forexample12:00 AM.
value
ADateobject.ADatecancontainadateandtime.
Examples
Thefollowingscriptpassesthevalueofafieldintherecordsettothedate()function.Thiswillonly
workifthetypeofthefieldhasbeensettoDateinthedatamappingconfigurationandifthefieldcon-
tainsavaliddate.
var myDate = formatter.date(records.fields.DATE, "MM/dd/yyyy");
Thecustompatternthatthescriptprovides,outputsthemonthanddayintwodigitseachandtheyear
infourdigits:05/21/2016.Formoreexamplesofformattingpatterns,see"Dateandtimepatterns"on
thefacingpage.
Creating a Date object from a string
InadatamappingconfigurationyoucansetthetypeofafieldtoDate,butwhenyouopenadatafileor
databaseintheDesignerwithoutadatamappingconfiguration,allfieldsaretextfields(fieldsofthe
typestring).Theformattercannotbeusedtoformatastringwithaparticulardateformat.The
solutionistostorethestringinavariableasaDateobject,andusetheformatterwiththatvariable.
Thefollowingsamplescriptdemonstratesthissolution.Itsplitsastringintopartsandthencreatesa
newDateobjectwiththepartsinthecorrectorder.ToconstructaDate,thepartsofthedatemustbe
Page 1179