Click here to Skip to main content
14,428,239 members
Rate this:
Please Sign up or sign in to vote.
See more:
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.


Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
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!
Rate this:
Please Sign up or sign in to vote.

Solution 2

' 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
'he didnt select a date
'punish him!
End If

Hope it helped you a bit :)
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100