Micro Focus QTP (UFT) Forums
Month calulation issue - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Month calulation issue (/Thread-Month-calulation-issue)



Month calulation issue - mv8167 - 01-05-2012

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?


RE: Month calulation issue - vIns - 01-05-2012

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


RE: Month calulation issue - mv8167 - 01-05-2012

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