query on date validations

zarina

Member
Joined
Nov 30, 2005
Messages
8
Programming Experience
Beginner
hi,
i hav used month calendar picker in my windows application need to know how to display a messagebox when from date is greater than to date provided i have used two calendars for each.

with regards,
zarina
 
Simple,

If datetimepicker1.text > datetimepicker2.text then
Messagebox.show("From Date must be before To Date!", "Date Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

...and you could also have it so that the user can't set the To Date before the From Date.

If datetimepicker2.text < datetimepicker1.text then
Messagebox.show("To Date must be after From Date!", "Date Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

...HTH
Luke

PS, you would need to replace your monthPickers with dateTimePickers
 
Last edited:
I am not sure that i understand well your question but probably this can help you for a while. Namely, to get the first date in selected date range, you can use the 'SelectionStart' property while if you want to get the last date you can use the 'SelectionEnd' property and finally you can compare these two with the other two from the second monthCalendar. Btw, if you don't want to allow the user to select a range but rather only a single date at a time then you can set the "MaxSelectionCount" property to 1 and then use either the SelectionStart or SelectionEnd properties to get the selected date.
Btw, why don't use DateTimePicker control that is much easier for manipulation in situation like your ...

HTH
Regards ;)
 
Back
Top