Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a form with three date picker controls. How can I validate that a user has actually selected a date (even if it is today). The dates will typically fall within range of about a month before to a month after the current date.

Thanks

R
Posted

When you use a DateTimePicker control, they always show a valid date time - that's the whole point. They never show or return an invalid date.

If you need to know that the user has changed it (or changed it and changed it back) then handle the ValueChanged event.
 
Share this answer
 
Comments
Richard.Berry100 31-Jan-13 12:31pm    
Oops my bad - I did not expect that the ValueChanged event would fire if you selected the current date. If they are selecting Today's date, I need to know that they intentionally chose Today's date, and did not forget to select the date - if that makes sense. I realize the date will always be a valid date. Thanks for the reply!
OriginalGriff 31-Jan-13 13:56pm    
You're welcome!
' Hello

' You can create a string like
Dim strDate as string

'Do something like this (sorry but i dont know the command from my head)
strDate = YourDateTimePicker.SelectedDate.ToString()

' Validation:
If strDate.Length > 0 then
'the user has selected a date
'you can continiue
Else
'he didnt select a date
'punish him!
End If

Hope it helped you a bit :)
 
Share this answer
 
Comments
Richard.Berry100 31-Jan-13 12:37pm    
Thanks for your answer - see my comment to OriginalGriff's answer. That way I can make sure they clicked the date - even if it is today's date

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900