Search code examples
.netwpfvisual-studioxceed

How to Extract Date and time ( in Hours, Minutes, Seconds, DayofWeek, Day, Month) from DateTimePicker? WPF extended toolkit by Xceed


I have WPF Extended Toolkit 3.5.0 (by Xceed), I'm using DateTimePicker control from here. I want to know that how to get selected Values of Hours, Minutes, Seconds, DayofWeek, Day, Month separately by DateTimePicker. Before this I was using telerik DateTimePicker Control Here I was using this approach to get these values

hours= DTPicker.SelectedTime.Value.Hours;
minutes= DTPicker.SelectedTime.Value.Minutes;
seconds= DTPicker.SelectedTime.Value.Seconds;
//for date
dayofweek= DTPicker.SelectedDate.Value.DayOfWeek;
day= DTPicker.SelectedDate.Value.Day;
month= DTPicker.SelectedDate.Value.Month;

But I couldn't find SelectedDate/SelectedTime/SelectedValue properties here. Thanks


Solution

  • The Value property returns a DateTime?:

    DateTime? value = dateTimePicker.Value;
    if (value.HasValue)
    {
        hours = value.Value.TimeOfDay.Hours;
        minutes = value.Value.TimeOfDay.Minutes;
        seconds = value.Value.TimeOfDay.Seconds;
        //for date
        dayofweek = value.Value.DayOfWeek;
        day = value.Value.Day;
        month = value.Value.Month;
    }
    

    You could basically just replace SelectedTime by Value in your current code.