Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# "A month number must be between 1 and 12" error in formula

Posted on 2008-10-27
Medium Priority
2,206 Views
I've created a report that will run for the last twelve months based on the current date (a rolling 12 month report).

I'd like to make some corresponding labels for the month values.  I was using this:
monthname (Month (CurrentDate), True)
monthname (Month (CurrentDate) - 1, True)
etc.

and it was working great until I got to month - 10.  Then I got this error:

A month number must be between 1 and 12

Any ideas?  Is there another way to accomplish my goal?  Also, I have to keep the labels short for space consideration which is why I need "Oct" instead of "October".

Steve
0
Question by:SStroz
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 77

Accepted Solution

peter57r earned 1600 total points
ID: 22810718
for previous months..
monthname (Month (dateadd("m",-1, CurrentDate) , True)
monthname (Month (dateadd("m",-2, CurrentDate) , True)
etc
0

LVL 16

Expert Comment

ID: 22812870
Peter is correct.

The problem that you are running into with taking a month minus 1 is that month is a number not a date, so 1-1 = 0 but Crystal then tries to reapply date functionality to it and errors cause there is no 0 month. I stress this to all of my developers, anytime you are doing a date modification use the dateadd function. It will prevent many issues down the road.
0

LVL 101

Expert Comment

ID: 22819129
I agree.  Good explanation.

It also solves the year issue.

mlmcc
0

LVL 7

Author Comment

ID: 22819212
peter57r,

When I try:
monthname (Month (dateadd("m",-10, CurrentDate) , True)

I get an error that "the ) is missing".  If I add a ")" at the end of the statement I get an error that Too many arguments have been given to this function.

What am I missing?

Steve
0

LVL 101

Assisted Solution

mlmcc earned 400 total points
ID: 22819269
Put it after CurrentDate

monthname (Month (dateadd("m",-10, CurrentDate) ), True)

mlmcc
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
###### Suggested Courses
Course of the Month6 days, 16 hours left to enroll