Something is wrong with DateString in Mathematica

If i type

DateString[{2011, 2, 29, 0, 0, 0}, {"DayName"}]

He gives "Tuesday".

And

DateString[{2011, 2, 29, 0, 0, 0}, {"DayName"}]

DateString[{2011, 3, 1, 0, 0, 0}, {"DayName"}]

+3
source share
2 answers
Needs["Calendar`"];
myDay[x_List] := DateString[x, {"DayName"}] /; DateQ[x]  

myDay[{2000, 1, 1}]
->"Saturday"

myDay[{2000, 13, 13}]
->myDay[{2000, 13, 13}]  

Of course, you can send a message (or Abort [] or something else) if you want:

Needs["Calendar`"];
Clear@myDay;
myDay[x_] /; If[DateQ[x], True, Message[myDay::nodate, x]; False] := 
                                                       DateString[x, {"DayName"}]
myDay::nodate = "The argument `1` is not a valid date.";
+6
source

It looks like the right behavior. The documentation for DateStringsays: "The values โ€‹โ€‹of m, d, h, m, s outside their normal ranges are accordingly reduced." what exactly happened: February 29 of this year is not, but if it were on the same day as March 1, which is really Tuesday.

+6
source

All Articles