I don't now how to validate date time picker controls....someone know?

Recommended Answers

All 9 Replies

What do you have to validate in dateTimepicker control? There is always a datetime selected (and shown). There cannot occur any error.
Explain what do you want to validate.

If you will use Value property of selected date, you will always get certain and real datetime value.

I need to achieve this:
– Can only accept future dates(from today to the future, not the past)
– Can only be AFTER departure date
- can only be in the past and NOT current
or future dates

1. dateTimePicker1.MinDate = DateTime.Today
2. dateTimePicker1.MinDate = new DateTime(2012, 2, 3) 'your departure date
3. 'dont know what it means

Anwyay, you see how you can set youur datetimepicker (use MinDate or MaxDate, to determine lower and upper date).

you can simply do this like this

'Can only accept future dates(from today to the future, not the past)
if datetimepicker.value.date >= now.date() then
' if true then code here
else
'if false then here
end if

'Can only be AFTER departure date 
if datetimepicker.value.date > departuredate then
'true then code here
else
'false code here
end if 
'can only be in the past and NOT current 
if datetimepicker.value.date< now.date() then
' true coding here
else
'false coding here
end if

if anyone find it wrong , its better to notify me not to press down arrow.

Regards

What if i want to make maxdate is not today, not the future? is it possible to do this way?

1. dateTimePicker1.MinDate = DateTime.Today
2. dateTimePicker1.MinDate = new DateTime(2012, 2, 3) 'your departure date
3. 'dont know what it means

Anwyay, you see how you can set youur datetimepicker (use MinDate or MaxDate, to determine lower and upper date).

It work waqasaslammmeo! thanks!

you can simply do this like this

'Can only accept future dates(from today to the future, not the past)
if datetimepicker.value.date >= now.date() then
' if true then code here
else
'if false then here
end if

'Can only be AFTER departure date 
if datetimepicker.value.date > departuredate then
'true then code here
else
'false code here
end if 
'can only be in the past and NOT current 
if datetimepicker.value.date< now.date() then
' true coding here
else
'false coding here
end if

if anyone find it wrong , its better to notify me not to press down arrow.

Regards

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If DateTimePicker2.Value.Date > DateTimePicker1.Value.Date Then
MsgBox("please insert proper date")

    End If
End Sub

do the above code to validate date time picker

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.