Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Vishal G.P 62 posts 122 karma points
    Jun 22, 2011 @ 21:59
    Vishal G.P
    0

    problem parsing datepicker value to DateTime with API

    hey guys,

     

    i have a strange problem. I have a "date with time" picker in one of my document types.

    When i select a date it shows as: 2011-06-15 18:14:00 in the field. No problem there..

    Now from code i get the property of the node: 

    DateTime.Parse(node.GetProperty("endDatetime").Value);

    but that gives me a "string was not recognized as a valid datetime" error... But i'm sure that the value of the property is correct.. cause if i write out the value alone.. i get 2011-06-15T18:14:00.. which looks pretty valid to me.. 

    I also tried :

    DateTime.ParseExact(node.GetProperty("startDatetime").Value,"yyyy-MM-dd H:mm", null);

    But that didnt help aswell.. 

    I know i must miss something.. so if you guys can help me out... i would really appreciate it..

     

    thanks alot..

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Jun 22, 2011 @ 22:18
    Steen Tøttrup
    1

    The date time you get is in the so-called XML datetime format, DateTime can not parse that, you'll need to use this method instead:

    System.Xml.XmlConvert.ToDateTime( "2011-06-15T18:14:00" )

    regards, Steen

  • Vishal G.P 62 posts 122 karma points
    Jun 22, 2011 @ 23:56
    Vishal G.P
    0

    great, this works, but when i dont choose a date in the datepicker the value i still get when reading the property is 0001-01-01T00:00:00, which i would think is the datetime.minvalue...

    But when i try to compare the above value with the dateTime.MinValue its false.. Is there a best practice to check for 'empty' dates in umbraco using API...

     

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Jun 23, 2011 @ 06:45
    Steen Tøttrup
    0

    Okay, that's a bit strange.

    I just did this in code:

                DateTime input = System.Xml.XmlConvert.ToDateTime("0001-01-01T00:00:00");
                Boolean same = (input == DateTime.MinValue);

    And same ended up being true, so I wonder why you're not getting the same result.

Please Sign in or register to post replies

Write your reply to:

Draft