Rad DateTimePicker - Invalid Date Format Exception

5 posts, 0 answers
  1. Diana
    Diana avatar
    18 posts
    Member since:
    Nov 2012

    Posted 11 Dec 2012 Link to this post

    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.
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 14 Dec 2012 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Diana
    Diana avatar
    18 posts
    Member since:
    Nov 2012

    Posted 15 Dec 2012 Link to this post

    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!

  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 19 Dec 2012 Link to this post

    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.
  6. Diana
    Diana avatar
    18 posts
    Member since:
    Nov 2012

    Posted 22 Dec 2012 Link to this post

    Thank you Peter :)
Back to Top
UI for WinForms is Visual Studio 2017 Ready