Say i have 2 date...
How to check if one is greater than the other...
For Example:
1/11/2004 > 28/ 10/2004
28/11/2004 > 27/10/2004
27/11/2004 > 27/11/2003
Thanks
Say i have 2 date...
How to check if one is greater than the other...
For Example:
1/11/2004 > 28/ 10/2004
28/11/2004 > 27/10/2004
27/11/2004 > 27/11/2003
Thanks
Hi
You can use the DateTime.CompareTo method.
Regards
Jorge
forget to add in some detail....
Start Date End Date
1/11/2004 > 28/ 10/2004 'Invalid Date
28/11/2004 > 27/10/2004 'Invalid Date
27/11/2004 > 27/11/2003 'Invalid Date
26/11/2004 < 27/11/2004 'Valid Date
It is not system date but the selection date between start and end...
Is it still use the DateTime.CompareTo since i want to compare only the date not time..
Thanks
Say that date is choosen by every combo box...
Start Day by one combo, month by another combo , year by textbox..
End Day got another set of that combo box and textbox..
which means all the date is not known until runtime when the user select from every combo box..
My Coding:
Error Message:Code:Dim DateState As Integer = Date.Compare(Date.FromOADate("(cboSDay.SelectedIndex + 1) & " / " & (cboSMonth.SelectedIndex + 1 )& " / " & (cboSYear.Text)"), Date.FromOADate("(cboEDay.SelectedIndex + 1) & " / " & (cboEMonth.SelectedIndex + 1) & " / " & (cboEYear.Text)"))
MessageBox.Show("Date are Equal")
ElseIf DateState < 0 Then
MessageBox.Show("Date 1 is greater than Date 2")
Else
MessageBox.Show("Date 2 is greater than Date 1")
End If
Does anyone know how to correct the error...Code:Additional information: Cast from string "(cboSDay.SelectedIndex + 1) & " to type 'Double' is not valid.
Thanks
finally, solve it...
I used the subtract method instead of DateTime.CompareTo method...
This is my coding:
:) :) :) :) :) :) :)Code:Dim DateState As Integer = CDate((cboSMonth.SelectedIndex + 1) & " / " & (cboSDay.SelectedIndex + 1) & " / " & (cboSYear.Text)).Subtract(CDate((cboEMonth.SelectedIndex + 1) & " / " & (cboEDay.SelectedIndex + 1) & " / " & (cboEYear.Text))).TotalDays
If DateState = 0 Then
MessageBox.Show("Date are equal")
ElseIf DateState < 0 Then
MessageBox.Show("Date 1 is greater than Date 2")
Else
MessageBox.Show("Date 2 is greater than Date 1")
End If
Another method which i get it from other forums using DateTime.CompareTo method...
Coding:
Code:Dim startDate As DateTime = DateTime.Parse(String.Format("{0}/{1}/{2}", cboSMonth.Text, cboSDay.Text, cboSYear.Text))
Dim endDate As DateTime = DateTime.Parse(String.Format("{0}/{1}/{2}", cboEMonth.Text, cboEDay.Text, cboEYear.Text))
Select Case DateTime.Compare(startDate, endDate)
Case -1
' smaller
MessageBox.Show("Date 2 is greater than Date 1")
Case 1
' bigger
MessageBox.Show("Date 1 is greater than Date 2")
Case 0
' same
MessageBox.Show("Date are Equal")
End Select