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

I'd like to write a function that behaves one way when the argument is a Mathematica date, such as {2013,12,15}, or with added hours, minutes and seconds if necessary. And the function needs to do something different with strings that will look like

2013 Month 02

I see that I can specify List, as in f[x_List] and f[x_String] that will do what I want as long as I don't mess up the arguments. Is there way to be more specific about the patterns that are allowed?

share|improve this question
You can be as specific as you want tutorial/Putting constraints on patterns Anything in particular? – ssch Oct 29 '13 at 1:56
so you only want to enter dates as lists or do you want to enter them as strings as well and differentiate between non-date strings? – Mike Honeychurch Oct 29 '13 at 2:04
I'll just use the standard mma format since I'm reading the dates in from a file. – Mitchell Kaplan Oct 29 '13 at 19:12
@MitchellKaplan Is it your earlier account: Mitchell Kaplan? If yes, the both should be merged. – Artes Oct 31 '13 at 16:10

There is a DateQ in the Calendar package. You can test the head of DateList["string"] to make your own dateStringQ. So f[x_?DateQ] and f[x_?dateStringQ] will do.

share|improve this answer
Thanks, I didn't know I could do that. – Mitchell Kaplan Oct 29 '13 at 19:12

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.