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

SelectedDate format

2 Answers 193 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Shane Ham
Top achievements
Rank 1
Shane Ham asked on 09 Mar 2009, 03:51 PM
I have a raddatetimepicker control with the dateFormat and displayDateFormat set to 'MM/dd/yyyy HH:mm'.
However, when I retrieve the SelectedDate from the code behind, it is in a different format 'MM/dd/yyyy HH:mm:ss'.

I do not want the seconds. How can I get around this problem?

2 Answers, 1 is accepted

Sort by
0
Shane Ham
Top achievements
Rank 1
answered on 09 Mar 2009, 03:58 PM
Just to clarify...

If I set the dateTime.SelectedDate = DateTime.Now() then
dateTime.SelectedDate.GetValueOrDefault(DateTime.MinValue)  returns something like 03/09/2009 10:57:28 even though the dateFormat is "MM/dd/yyyy HH:mm".  I would at least expect the seconds component to be 00 when formatted this way.

Perhaps this is expected behavior because the actual value set DateTime.Now does have the seconds component.
I still need a workaround. Would overriding the SelectedDate property be the best approach?

0
Daniel
Telerik team
answered on 12 Mar 2009, 05:05 PM
Hello Shane,

Please try the following approach:
string myDate = RadDatePicker1.SelectedDate.Value.ToString(RadDatePicker1.DateInput.DateFormat); 

<telerik:RadDatePicker ID="RadDatePicker1" runat="server" SelectedDate="09/09/2009"
    <DateInput runat="server" DisplayDateFormat="MM/dd/yyyy HH:mm" DateFormat="MM/dd/yyyy HH:mm" 
        SelectedDate="09/09/2009" /> 
</telerik:RadDatePicker> 

Let me know whether this helps.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Calendar
Asked by
Shane Ham
Top achievements
Rank 1
Answers by
Shane Ham
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or