Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Month calulation issue
#1
Solved: 10 Years, 9 Months ago
Currently I have the following code:

Code:
intMonth = Month(Now)                          ' 9
ThisMonth = MonthName(intMonth)           ' "September"
Min1Month = MonthName(intMonth - 1)     ' "August"
Min6Month = MonthName(intMonth  - 6)

As is (which i just now found out in January) that when Now = 1, thus intMonth = 1, and Min1Month = 0.

When Now is <= 6, thus Min6Month = -5 to 0

What code is approprioate to use in both cases? How can I keep Min1Month and Min6Month between 1 and 12?

I have tried a few wzys other than going to a If Then for each case.

Thoughts?
Reply
#2
Solved: 10 Years, 9 Months ago
Hi..
i just tried this...

Code:
MonthName(( intMonth - i +11 )mod 12 +1)

this will return correct values..
here i is 0 to 11
i=1- for last month
i=6 -6 months ago
Reply
#3
Solved: 10 Years, 9 Months ago
vIns

thx for the help. I will look up what the "mod 12 + 1" does to better understand this. I am guessing that this is vbScript?

So, I will try

Code:
intMonth = Month(Now) ' 1
ThisMonth = MonthName(intMonth)
Min1Month = MonthName(( intMonth - 1 +11 )mod 12 +1)
Min6Month = MonthName(( intMonth - 6 +11 )mod 12 +1)

etc...

UPDATE:

vIns, Your code worked perfectly for me. Thxxxxxxxx
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Month name select from WebList Box kamalakannan_anandan 2 4,041 07-06-2011, 09:52 AM
Last Post: rajpes

Forum Jump:


Users browsing this thread: 1 Guest(s)