|
-
Oct 18th, 2004, 11:16 AM
#1
Thread Starter
Addicted Member
VB.NET: Check Date, Inputs from different comboBox...[Resolved]
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
Last edited by toytoy; Oct 20th, 2004 at 05:30 AM.
-
Oct 18th, 2004, 11:49 AM
#2
Hi
You can use the DateTime.CompareTo method.
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Oct 18th, 2004, 11:08 PM
#3
Thread Starter
Addicted Member
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
-
Oct 19th, 2004, 07:58 AM
#4
Thread Starter
Addicted Member
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:
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
Error Message:
Code:
Additional information: Cast from string "(cboSDay.SelectedIndex + 1) & " to type 'Double' is not valid.
Does anyone know how to correct the error...
Thanks
Last edited by toytoy; Dec 3rd, 2004 at 07:56 AM.
-
Oct 20th, 2004, 05:26 AM
#5
Thread Starter
Addicted Member
Last edited by toytoy; Dec 3rd, 2004 at 07:56 AM.
-
Oct 20th, 2004, 07:26 AM
#6
Thread Starter
Addicted Member
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
Last edited by toytoy; Dec 3rd, 2004 at 07:57 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|