Date Comparison

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a problem in comparing two dates.when i compare two dates it's only
taking the days into consideration.for example when i select 10th may 2004 as
my first date and 1st may 2004 as my second date,it will say that 10th may is
greater.what might be the problem.please help me
Thanks in advance.
 
please put up a small snippet of code that illustrates the actual problem
you are having and describe the behavior that you are expecting.

Your message appears to demonstrate expected behavior. (May 10th, '04 is
greater than May 1st, '04)

--- Nick
 
Kurien,

Basicly it is the best to compare dates in the datetime format that goes
right in all culturesettings in the world
VB code
\\\
dim a as datetime = new datetime(2004,5,10)
dim b as datetime = new datetime(2004,5,10
if a > b etc.
///

I hope this helps?

Cor
 
I've been following the conversation. Looks like Cor may have hit on the
problem. I'd like to add a little to his excellent response.

Kurien,
We assume that you are first declaring your variables:
Dim CalendarDate1, CalendarDate2

You should first change these statements to:
Dim CalendarDate1 as DateTime
Dim CalendarDate2 as DateTime

Secondly, you should not convert the values to string before comparing them:

Private Sub Calendar1_Click()
CalendarDate1 = Calendar1.Value '<-- notice the change here
Command1.Enabled = False
MsgBox CalendarDate1.Format("dd-MM-yyyy") '<-- notice the change here
End Sub


Hope this helps,
--- Nick
 
Nick,
One minor correction:
MsgBox CalendarDate1.Format("dd-MM-yyyy") '<-- notice the change here

MsgBox CalendarDate1.ToString("dd-MM-yyyy") '<-- notice the change
here

Otherwise I concur with you & Cor.

Hope this helps
Jay
 
Doh stupid me I was just changing text typed it and using Cstr, which I
normally never use.
Otherwise I concur with you & Cor.

me too Jay, I corrected it at the original message.

nock nock nock nock on my head

thanks,

Cor
 
Back
Top