# How to convert dayname to number?

When I input DayName[{2012,12,24}] I get Monday as output. What is the most effective way to convert Monday into 1, Tuesday into 2 etc.?

To do this, I can create a length-7 array to store all the day-name and then do some matching and return the matched position. But that approach is too clumsy. Is there any other lighter and faster way?

The most efficient way is not to use DayName but this:

DateValue[{2012, 12, 24}, "ISOWeekDay"]


Regarding Robert's comment

Well, that was a correct answer but not on the exact question. What if I don't have a date but just a weekday as e.g. Monday how do I now get the ISOWeekDay number. Without explicitly coding. Is there a a ready to use MMA function f with f[Monday] == 1

the shortest solution I found is

ISODay = SystemDateObjectDump\$dowAssociation;

ISODay[Monday]
(* 1 *)

• Well, that was a correct answer but not on the exact question. What if I don't have a date but just a weekday as e.g. Monday how do I now get the ISOWeekDay number. Without explicitly coding. Is there a a ready to use MMA function f with f[Monday] == 1 – Robert Nowak Jul 18 '19 at 18:14
• @RobertNowak See my edit above. – halirutan Jul 18 '19 at 18:59
• May I ask by which black spell incantation you discovered this dowAssociation? – Roman Jul 18 '19 at 21:05
• I was quite sure that at some point, WL's functions need a conversion from day-name to number, because how else would they implement the "ISOWeekDay". So I started digging with PrintDefinitions[DateValue] and followed the trail... – halirutan Jul 19 '19 at 13:02
ISODay[day_] := Mod[With[{o = {1, 1, 0}}, DateDifference[
DayPlus[o, 1, Monday],
DayPlus[o, 1, day]
][[1]]], 7] + 1