jakester
Jan 11, 2011, 01:26 PM
Jerry, you'll probably be the one to respond so I'll just post this for you.
I'm trying to compare some date values using VBA and the issue I'm having is that my code is treating date values that are older than more recent values as greater. So, if you were to run the code below you'd see that it's returning EOPM instead of BOCM. Well, that can't be right because Dec 31, 2010 is not a greater date value than 1/1/11.
I won't get into what I'm using this for or any of that because it would take me awhile to explain that and I don't have that kind of time. If you have any suggestions, I'd greatly appreciate it.
BOPM = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "mm.dd.yy") ' Begin of Prev Month
EOPM = Format(DateSerial(Year(Date), Month(Date), 0), "mm.dd.yy") 'End of Prev Month
BOCM = Format(DateSerial(Year(Date), Month(Date), 1), "mm.dd.yy") 'Begin of Curr Month
EOCM = Format(DateSerial(Year(Date), Month(Date) + 1, 0), "mm.dd.yy") 'End of Curr Month
MRD = Format(Date - 1, "mm.dd.yy")
date1 = Format(Date - 1, "mm.dd.yy")
date2 = Format(Date - 2, "mm.dd.yy")
date3 = Format(Date - 3, "mm.dd.yy")
If BOCM > EOPM Then
MsgBox ("BOCM")
Else
MsgBox ("EOPM")
End If
End Sub
I'm trying to compare some date values using VBA and the issue I'm having is that my code is treating date values that are older than more recent values as greater. So, if you were to run the code below you'd see that it's returning EOPM instead of BOCM. Well, that can't be right because Dec 31, 2010 is not a greater date value than 1/1/11.
I won't get into what I'm using this for or any of that because it would take me awhile to explain that and I don't have that kind of time. If you have any suggestions, I'd greatly appreciate it.
BOPM = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "mm.dd.yy") ' Begin of Prev Month
EOPM = Format(DateSerial(Year(Date), Month(Date), 0), "mm.dd.yy") 'End of Prev Month
BOCM = Format(DateSerial(Year(Date), Month(Date), 1), "mm.dd.yy") 'Begin of Curr Month
EOCM = Format(DateSerial(Year(Date), Month(Date) + 1, 0), "mm.dd.yy") 'End of Curr Month
MRD = Format(Date - 1, "mm.dd.yy")
date1 = Format(Date - 1, "mm.dd.yy")
date2 = Format(Date - 2, "mm.dd.yy")
date3 = Format(Date - 3, "mm.dd.yy")
If BOCM > EOPM Then
MsgBox ("BOCM")
Else
MsgBox ("EOPM")
End If
End Sub