Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Comparing dates

Status
Not open for further replies.

brendasql

Programmer
Apr 1, 2003
58
US
I am having a serious problem trying to compare dates. I am trying to compare a specific month like someone's birthmonth to another specific month like one that has been stored as an Issue date. An example of the problem is that I have a person with a birth month of February (2) and an Issue date with the month of October (10), well...I always thought that 2 was less than 10, but according to my code in VB6 it is not. Here's an example of my code please help!!!!

Dim theBirthMonth as String
Dim theIssueMonth as String

theBirthMonth = Month(dtDOB)
theIssueMonth = Month(dtIssue)

If theBirthMonth <= theIssueDate then
&quot;I'll do this&quot;
Else
&quot;I'll do something different&quot;
End IF

Please explain why if theBirthMonth is 2 it is not less than theIssueMonth of 10, works fine if birth month is 10, 11 or 12.
 
See if this helps.
Dim theBirthMonth as INTEGER
Dim theIssueMonth as INTEGER
 
The reason you're getting 10 being less than 2 is because you're comparing strings, not numbers. &quot;1&quot; comes before &quot;2&quot; in the character set. So &quot;10&quot; < &quot;2&quot;.

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;A computer program does what you tell it to do, not what you want it to do.&quot; -- Greer's Third Law
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top