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

Rad DateTimePicker - Invalid Date Format Exception

4 Answers 151 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Diana
Top achievements
Rank 1
Diana asked on 11 Dec 2012, 04:40 PM
Hello,

I use a Rad DateTimePicker in a certain application. What I want to achieve is to get the date that the user selects, along with the time of course, and send those using JScript to an asmx webservice as one of its arguments. What I did was that I sent the datetime as string from the JScript file and in the webservice I tried to parse that string back to datetime format using convert.todatetime method and I tried several other conversion methods but my problem was always one; and that is the string that's being sent is not recognized as a correct "convertible" datetime.

I debugged, and it's always sent as, for example, "2012-12-13-08-02-05" [this corresponds to 13/12/2012 08:02:05]. As you can see, this string really is not in one of the acceptable formats that the parsing methods accept.

I tried to change the input dateformat of the datetimepicker and it does change but only in displaying; it does not change in the string according to what I want [I mean the format I set is reflected on display only and not on save]. 

I'd really appreciate your help, thank you.

4 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 14 Dec 2012, 09:50 AM
Hi Diana,

Thank you for writing.

The type of RadDateTimePicker's Value property is DateTime. You should parse manually your XML/Text date to the .NET type DateTime and pass the result to the Value property and vice versa - you should manually compose the desired output format from the Value property (which is .NET type DateTime)

Let me know if you have additional questions.

Kind regards,
Peter
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Diana
Top achievements
Rank 1
answered on 15 Dec 2012, 04:42 PM
Hello Peter,

Thank you for replying.

In my case I use JQuery to retrieve the selected date like this:

var SelectedDate = dpTest.val();

When I debug, I find that the "SelectedDate" variable type here is "String". And it's in the format I mentioned before, that is for example, "2012-12-13-08-02-05" [corresponding to 13/12/2012 08:02:05]. And after sending this value to the asmx webservice end, it's received in the same format: "2012-12-13-08-02-05" [corresponding to 13/12/2012 08:02:05].

When, in the webservice, I write:

Dim _FormattedDate As Datetime =  Convert.ToDateTime(SelectedDate)

I get an error when I run this that the received String, that is "SelectedDate" is not recognized to be in a valid Datetime format.

My question, put in another way, would be: is there any way to manipulate the String that is produced from "dpTest.val()" in the first place to be in a valid recognizable Datetime format? To be specific, in the format "dd/MM/yyyy HH:mm:ss"?

Thanks again!

0
Peter
Telerik team
answered on 19 Dec 2012, 03:24 PM
Hello Diana,

Thank you for sharing these details with us.

As I mentioned before you should parse manually the date in your format to DateTime. I am not sure that Convert.ToDateTime can work with your format - you can refer to this code project article to see how to convert manually your format.

I hope helps.

Kind regards,
Peter
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Diana
Top achievements
Rank 1
answered on 22 Dec 2012, 05:04 PM
Thank you Peter :)
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Diana
Top achievements
Rank 1
Answers by
Peter
Telerik team
Diana
Top achievements
Rank 1
Share this question
or