# 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 Commented Jul 18, 2019 at 18:14
• @RobertNowak See my edit above. Commented Jul 18, 2019 at 18:59
• May I ask by which black spell incantation you discovered this dowAssociation? Commented Jul 18, 2019 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... Commented Jul 19, 2019 at 13:02
ISODay[day_] := Mod[With[{o = {1, 1, 0}}, DateDifference[
DayPlus[o, 1, Monday],
DayPlus[o, 1, day]
][[1]]], 7] + 1