({{, (RefLink[DatePattern, paclet:ref/DatePattern])[{"(Subscript[e, 1])","(Subscript[e, 2])",…}] 
represents the characters of a date with elements of type "(Subscript[e, i])" in (RefLink[StringExpression, paclet:ref/StringExpression]).}, {, (RefLink[DatePattern, paclet:ref/DatePattern])[{"(Subscript[e, 1])","(Subscript[e, 2])",…},sep]
allows separators that match the string expression sep.}})

OpenersNotesSection(Spacer1)Details

Possible element types "(Subscript[e, i])" are: "Year", "Quarter", "Month", "MonthName", "Day", "DayName", "Hour", "AMPM", "Minute", "Second".

If no explicit separator is specified, the "(Subscript[e, i])" must be separated by /, -, :, or . characters.

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Compare a string to a list of date elements:

StringMatchQ["3/15/1984",DatePattern[{"Month","Day","Year"}]]

Compare to a list of time elements:

StringMatchQ["00:38:16",DatePattern[{"Hour","Minute","Second"}]]

Compare to a pattern with all separators explicitly given:

StringMatchQ["Wed, 15 Nov 2006",DatePattern[{"DayName",", ","Day"," ","MonthName"," ","Year"}]]

OpenersExampleSection1(Spacer1)Scope  (2)

Date elements do not match out-of-range values:

StringMatchQ["3/15/1984",DatePattern[{"Day","Month","Year"}]]

Test a string allowing only "/" characters as separators:

StringMatchQ["12/10/06",DatePattern[{"Year","Month","Day"},"/"]]

Test the same string allowing only colon separators:

StringMatchQ["12/10/06",DatePattern[{"Year","Month","Day"},":"]]

OpenersExampleSection2(Spacer1)Applications  (1)

Define a function only for month, year strings:

f[dt_?(StringMatchQ[#,DatePattern[{"Month","Year"}]]&)]:=AbsoluteTime[dt]

f["5/2007"]

The function returns unevaluated for other input patterns:

f["1/2/3"]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

(RefLink[DateString, paclet:ref/DateString]) gives results that match a date pattern:

DateString[{"Hour",":","Minute"}]

StringMatchQ[%,DatePattern[{"Hour",":","Minute"}]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DateList, paclet:ref/DateList])  ▪  (RefLink[DateString, paclet:ref/DateString])  ▪  (RefLink[DateFunction, paclet:ref/DateFunction])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Working with String Patterns, paclet:tutorial/WorkingWithStringPatternsOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Date & Time, paclet:guide/DateAndTime])}, {▪(RefLinkPlain[String Patterns, paclet:guide/StringPatterns])}})}})