Mr. Xek
Mr. Xek

Reputation: 91

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

Upvotes: 0

Views: 616

Answers (2)

jedipi
jedipi

Reputation: 175

Assume that you have named your Toolkit DateTiemPicker as DTPicker.

<toolkits:DateTimePicker Value="{Binding LastUpdated}" Format="FullDateTime" Width="200" Height="30" Name="DTPicker"/>

Then you can get all the value you need as below.

var seledtedDateTime = DTPicker.Value;
if (seledtedDateTime.HasValue)
{
    var hours = seledtedDateTime.Value.Hour;
    var minutes = seledtedDateTime.Value.Minute;
    var seconds = seledtedDateTime.Value.Second;
    var dayofweek = seledtedDateTime.Value.DayOfWeek;
    var day = seledtedDateTime.Value.Day;
    var month = seledtedDateTime.Value.Month;
}

Upvotes: 1

mm8
mm8

Reputation: 169370

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.

Upvotes: 1

Related Questions