How to get date and time components

3 posts, 0 answers
  1. Michael
    Michael avatar
    6 posts
    Member since:
    Feb 2011

    Posted 17 Dec 2012 Link to this post

    I am attempting to do the following:

    EventToPost.BeginsDateTime = radDatePickerBegin.Date + radTimePickerBegin.TimeOfDay;

     
    Date, however, is not a property of the radDatePicker and neither is TimeOfDay a property of radTimePicker. It seems that they both will return only .Value which in both cases is a DateTime. This means that to set the BeginsDateTime property in EventToPost, I need to do some messy conversion and extraction of date and time values respectively so that I can add the time component to the date component.

    What am I missing here?

    Michael
  2. Michael
    Michael avatar
    6 posts
    Member since:
    Feb 2011

    Posted 17 Dec 2012 Link to this post

    It looks like I've figured out a way to solve the problem.

      TimeSpan EndsDateTimeSpan = (TimeSpan)(radTimePickerEnd.Value - radDatePickerEnd.Value);
      EventToPost.EndsDateTime = (DateTime)(radDatePickerEnd.Value - EndsDateTimeSpan);

    radDatePicker seems to remove the time component (as expected) while radTimePicker does not (not intuitive, but I understand why). So the solution is to subtract the value of radDatePicker from that of radTimePicker which yields a TimeSpan. This in turn can be added to the radDatePicker.Value to obtain the combined Date and Time values.

    It would be very handy to be able to directly access the time value from the radTimePIcker as a TimeSpan which is what I was expecting.

    Michael
  3. DevCraft banner
  4. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 17 Dec 2012 Link to this post

    Hello Michael,

    RadDatePicker and RadTimePicker both work with DateTime values. The RadTimeSpanPicker control works with TimeSpan values.

    Let me know if you have further questions or need assistance.

    Greetings,
    Deyan
    the Telerik team
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Back to Top