DatePciker return only date

5 posts, 1 answers
  1. Brett
    Brett avatar
    40 posts
    Member since:
    Mar 2008

    Posted 31 Jul 2008 Link to this post

    I'm sending the selected date to a label. I'm using lblDate.Text = RadDatePicker1.SelectedDate.ToString(); and I'm getting the date and time and I'd like to format it just as the date.

    I tried lblQuoteDate.Text = RadDatePicker1.SelectedDate.ToString("MM/dd/yyyy"); but no dice.

    Any suggestions would be much appreciated.

    Thanks,

    Brett
  2. Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 31 Jul 2008 Link to this post

    Hello Brett,

    Try using the ToShortDateString() method on the DateTime object. Here is an example:

    1 protected void RadCalendar1_SelectionChanged(object sender, SelectedDatesEventArgs e) 
    2
    3     Label1.Text = RadCalendar1.SelectedDate.ToShortDateString(); 
    4

    I hope this helps. If you have further questions, please don't hesitate to ask.

    Regards,
    Kevin Babcock
  3. Brett
    Brett avatar
    40 posts
    Member since:
    Mar 2008

    Posted 31 Jul 2008 Link to this post

    I tried with the RadDatePicker, it does exactly what I want. I'm using RadDatePicker though, but why doesn't RadDatePicker not have a .ToShortDateString(); ?

    Thanks,

    Brett
  4. Answer
    Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 31 Jul 2008 Link to this post

    Hello Brett,

    The ToShortDateString() is a member of the System.DateTime class, and not something provided by Telerik. In order to use this method, you simply need to extract the DateTime object of your RadDatePicker. You can do this by getting the SelectedDate.Value property of your RadDatePicker. Here is an example:

    1 protected void RadCalendar1_SelectedDateChanged(object sender, SelectedDateChangedEventArgs e) 
    2
    3     // Use the SelectedDateChangedEventArgs object 
    4     Label1.Text = e.NewDate.Value.ToShortDateString(); 
    5  
    6     // Use the RadDatePicker's SelectedDate property 
    7     Label1.Text = RadDatePicker1.SelectedDate.Value.ToShortDateString(); 
    8

    If you have further questions, please let me know.

    Sincerely,
    Kevin Babcock
  5. Brett
    Brett avatar
    40 posts
    Member since:
    Mar 2008

    Posted 31 Jul 2008 Link to this post

    Thank you, Kevin, worked perfectly.

    Brett
Back to Top