Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This answer notes that Calendar package has a function DateQ but the documentation suggests that the input is limited to a fixed format YY,MM,DD etc. Is there a more robust way to check any String for date-form ?

(Self answer, below)

share|improve this question
Use DatePattern – Mike Honeychurch Jun 4 '14 at 23:11
up vote 4 down vote accepted

A simpler version very similar in spirit to your own solution:

dateQ = Composition[Quiet, NumberQ, AbsoluteTime]
share|improve this answer
Very elegant. Accepted – PlaysDice Jun 4 '14 at 20:00

Rather than creating your own function, the built in way to check any string is to use StringMatchQ and DatePattern. From the docs:


enter image description here

share|improve this answer
Looks like this is the right way! – Szabolcs Jun 4 '14 at 23:44
Mike- nice and a +1. I'm going to stick with Szabolcs' approach as it works across all the test cases without prior knowledge of the formatting. The use-case was checking data from a spreadsheet that had a variety of date formats. – PlaysDice Jun 5 '14 at 0:10

One basic approach:

refDate = "Jan 1 2012";
dateQ[input_] :=
 !TrueQ@Quiet@Check[DateDifference[input, refDate], True]


test={"dog",dog,"Jan 1 2012", "January 1 2012", "1/1/2012","1/1/12","Q2 2014", "2014 Q1","2014Q2"};
{False, False, True, True, True, True, True, True, True}

Of course, this approach could be further modified to pass values for Calander-> and suitable refDate to the function.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.