This is a migrated thread and some comments may be shown as answers.

DatePciker return only date

4 Answers 100 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 31 Jul 2008, 08:39 PM
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

4 Answers, 1 is accepted

Sort by
0
Kevin Babcock
Top achievements
Rank 1
answered on 01 Aug 2008, 12:47 AM
Hello Brett,

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

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

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

Regards,
Kevin Babcock
0
Brett
Top achievements
Rank 1
answered on 01 Aug 2008, 01:27 AM
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
0
Accepted
Kevin Babcock
Top achievements
Rank 1
answered on 01 Aug 2008, 01:52 AM
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:

protected void RadCalendar1_SelectedDateChanged(object sender, SelectedDateChangedEventArgs e) 
    // Use the SelectedDateChangedEventArgs object 
    Label1.Text = e.NewDate.Value.ToShortDateString(); 
 
    // Use the RadDatePicker's SelectedDate property 
    Label1.Text = RadDatePicker1.SelectedDate.Value.ToShortDateString(); 

If you have further questions, please let me know.

Sincerely,
Kevin Babcock
0
Brett
Top achievements
Rank 1
answered on 01 Aug 2008, 02:08 AM
Thank you, Kevin, worked perfectly.

Brett
Tags
Calendar
Asked by
Brett
Top achievements
Rank 1
Answers by
Kevin Babcock
Top achievements
Rank 1
Brett
Top achievements
Rank 1
Share this question
or