VB.NET - vb.net datetimepicker control - Asked By silna chandra on 24-Apr-09 01:27 AM

hi

Which are the diff methods to validate the date time in datetimepicker when user selects an invalid date?

Thanks

silna


I hope you cannot select worng date or enter wrong date in datetime picker control

Vasanthakumar D replied to silna chandra on 24-Apr-09 01:35 AM

Hi,

if you want to restrcit the datetime limit,

you can use mindate and maxdate as

like this

dateTimePicker1.MinDate = DateTime.Now.AddDays(-10);

dateTimePicker1.MaxDate = DateTime.Now.AddDays(10);

Use these - [)ia6l0 iii replied to silna chandra on 24-Apr-09 01:58 AM

You can do the following in the datetimepicker control in vb.net.

1. You can restrict the date to a custom format. Look for a customFormat option in the properties, where you could set values like mm/dd/yyyy, dd/mm/yyyy..,.etc

2. You can use the MinDate and MaxDate properties to restrict the boundary of dates, that can be selected in the datetimepicker control.

3. You can set the datetime format in the "Format" Property of the datetimepicker control.

4. And you can validate the dates in the CloseUp Event like this.

Private Sub dtBeginDatePicker_CloseUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtBeginDatePicker.CloseUp
        If Me. dtBeginDatePicker.Value > Me. dtEndDatePicker.Value Then
            Me. dtEndDatePicker.Value = Me. dtBeginDatePicker.Value
        End If
End Sub

Private Sub dtEndDatePicker_CloseUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtEndDatePicker.CloseUp
      If Me.dtEndDatePicker.Value < Me.dtBeginDatePicker.Value Then
          Me.dtBeginDatePicker.Value = Me.dtEndDatePicker.Value
      End If
End Sub

validate date - Ravenet Rasaiyah replied to silna chandra on 24-Apr-09 07:34 AM

Hi

Best idea here
you need write method to valid, say get user selected date

datetime date=dpickter.Selectedvalue;

if(date >here you condition) // decide you date condition then write
{
//implement
}

thank you