What's wrong with my code.......???????
Help!! I cannot get correct value after I minus both Month value...
lblValue.Caption = Month(CDate("May-2009") - CDate("Mar-2009"))
The result suppose have to get lblValue.Caption = "2" but I get lblValue.Caption = "3"...
what's wrong with this simple minus code?
Re: What's wrong with my code.......???????
This is what happened:
Code:
lblValue.Caption = Month(CDate("May-2009") - CDate("Mar-2009"))
lblValue.Caption = Month(#5/1/2009# - #3/1/2009#)
lblValue.Caption = Month(61)
lblValue.Caption = Month(CDate(61))
lblValue.Caption = Month(#3/1/1900#)
lblValue.Caption = 3
If you don't care about the year, change it to:
Code:
lblValue.Caption = Month(CDate("May-2009")) - Month(CDate("Mar-2009"))
Otherwise use DateDiff() function:
Code:
lblValue.Caption = DateDiff("m", CDate("Mar-2009"), CDate("May-2009"))
Re: What's wrong with my code.......???????
Quote:
Originally Posted by anhn
This is what happened:
Code:
lblValue.Caption = Month(CDate("May-2009") - CDate("Mar-2009"))
lblValue.Caption = Month(#5/1/2009# - #3/1/2009#)
lblValue.Caption = Month(61)
lblValue.Caption = Month(CDate(61))
lblValue.Caption = Month(#3/1/1900#)
lblValue.Caption = 3
If you don't care about the year, change it to:
Code:
lblValue.Caption = Month(CDate("May-2009")) - Month(CDate("Mar-2009"))
Otherwise use DateDiff() function:
Code:
lblValue.Caption = DateDiff("m", CDate("Mar-2009"), CDate("May-2009"))
I use the third solution
Code:
lblValue.Caption = DateDiff("m", CDate("Mar-2009"), CDate("May-2009"))
It's works what excacly I want.... Thanks~~~