Skip to main content
Ben Nadel at CFCamp 2023 (Freising, Germany) with: Patrick Trüssel
Ben Nadel at CFCamp 2023 (Freising, Germany) with: Patrick Trüssel

19.0 Must Be Within Range: ( 1 : 12 )

By
Published in Comments (8)

I was just helping someone debug a strange ColdFusion error:

19.0 Must Be Within Range: ( 1 : 12 ). ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.

Because ColdFusion wasn't giving us any template or line numbers, we basically had to start commenting out code and putting it back in until we narrowed down the template and the line. And, seeing as I was not working on the project, this was particularly necessary (as I was not familiar with the code at all - just called over for the error). Finally, we narrowed it down to the ColdFusion method, MonthAsString(). This takes a month index and returns the name of the month. Therefore, running:

#MonthAsString( 1 )#

... gives us:

January

The values, obviously, can only be 1 - 12, as there are only 12 months in the year. As it turns out, there was some weird math algorithm that was passing a variable of the value 19 to the MonthAsString() function; hence the whole out of range error.

Good to know if I ever see this error again.

Want to use code from this post? Check out the license.

Reader Comments

3 Comments

When I was a kid I ran across a few page insert in a day planner that had a system to calculate the day of week (Monday, Thursday, etc.) of any date between around 1500 and 2100. Years later I realized it was based on an algorithm that works for our current calendar system(Gregorian).

I suspect the 19 is a remnant of the formula. The days of week fall on a fairly predictable basis for hundreds of years based on a relatively easy formula.

http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
http://www.jimloy.com/math/day-week.htm

9 Comments

I recently had a similar ColdFusion error with no line number information to help:
11.0 must be within range: ( 1 : 7 )

The date in my Form variable was "11/11/2009" and I was doing this:
DayOfWeekAsString(Day(Form.menu_dt)

After finding this blog entry, I quickly discovered I was out of the range for days in a week and fixed the inner function call:
DayOfWeekAsString(DayOfWeek(Form.menu_dt)

16 Comments

Just hit this one myself, but wasn't having any luck with it.

<cfswitch expression="#dayofweek(now())#">
<cfcase value="1,7">Weekend</cfcase>
<cfcase value="2">Monday</cfcase>
<cfdefaultcase>Other Day</cfdefaultcase>
</cfswitch>

finally realized... it was because I was outputting #DayOfWeekAsString(NOW())# to get the name of the "Other Day" in some text... As with Troy above, adding dayofweek() into the mix fixed it.

Really strange and unexpected behavior for me.. usually coldfusion is so friendly that it just does that sort of conversion behind the scenes for you.

15,848 Comments

@JC,

Yeah, especially with dates - you can throw just about anything at ColdFusion and, chances are, it can convert it to a date :)

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel