Solved Trying to Get December months No. '12'

January 3, 2012 at 09:44:00
Specs: Windows XP
Hi guys,

I am trying to populate numbers for months and using following if Condition. Its working fine except for December:-

IF(MONTH(TODAY())-1<10,"0"&MONTH(TODAY())-1,MONTH(TODAY())-1)

Can anyone please help?


See More: Trying to Get December months No. 12

Report •


✔ Best Answer
January 4, 2012 at 05:15:32
This should get you what you want:

=IF(MONTH(TODAY())=1,12,IF(MONTH(TODAY())-1<10,"0"&MONTH(TODAY())-1,MONTH(TODAY())-1))

You should also be aware that by pre-pending the zero as TEXT with the "0"&
you make the whole month number TEXT, not a number.

MIKE

http://www.skeptic.com/



#1
January 3, 2012 at 11:57:13
The MONTH() function does not work the way you think it does.

Using the MONTH() function returns the month as an integer,
ranging from 1 (January) to 12 (December).

So trying to subtract 1 from 1 gets you zero.

MIKE

http://www.skeptic.com/


Report •

#2
January 3, 2012 at 22:56:03
What exactly are you trying to do?

What does "populate numbers for months " mean?

Examples work best when trying to clarify things.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#3
January 4, 2012 at 05:02:59
I want 12 as result of this.

Report •

Related Solutions

#4
January 4, 2012 at 05:15:32
✔ Best Answer
This should get you what you want:

=IF(MONTH(TODAY())=1,12,IF(MONTH(TODAY())-1<10,"0"&MONTH(TODAY())-1,MONTH(TODAY())-1))

You should also be aware that by pre-pending the zero as TEXT with the "0"&
you make the whole month number TEXT, not a number.

MIKE

http://www.skeptic.com/


Report •


Ask Question