Copied to clipboard

Flag this post as spam?

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


  • Barbacan 29 posts 79 karma points
    Jul 13, 2014 @ 23:23
    Barbacan
    0

    Format date error

    Hello, in this snippet:

    @item.GetPropertyValue("dataArticolo").ToString()

    I would like to format the date as "dd/MM/yyy". If I try to use this as ToString() argument, I got an error. Without any dateTime format, the date apprear as:
    2014-09-17T00:00:00

    Any hints?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 14, 2014 @ 00:01
    Dennis Aaen
    0

    Hi Barbacan,

    What if you do something like this:

    @item.GetPropertyValue<DateTime>("dataArticolo").ToString("dd/MM/yyyy")

    Hope this helps,

    /Dennis

  • Barbacan 29 posts 79 karma points
    Jul 14, 2014 @ 09:58
    Barbacan
    0

    Hi Dennis,
    in this case I got an ("dataArticolo").ToString("dd/MM/yyyy"), basically it does not print out the value itself.

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 14, 2014 @ 10:06
    Dennis Aaen
    1

    Hi Barbacan,

    How about this?

    @(item.GetPropertyValue<DateTime>("dataArticolo").ToString("dd/MM/yyyy"))
    

    Try to see this post: http://our.umbraco.org/forum/using/ui-questions/44732-cannot-format-DateTime-using-umbracolibraryFormatDateTime%28%29

    Hope this helps,

    /Dennis

  • Barbacan 29 posts 79 karma points
    Jul 14, 2014 @ 10:36
    Barbacan
    0

    Damn, I could'nt get thru this. I checked the logfile, there's an exception concerning the ToString method.
    "The best overloaded method match for 'string.ToString(System.IFormatProvider)' has some invalid arguments"

    I'm goingo to investigate, never had an stupid issue like this

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jul 15, 2014 @ 10:18
    Mike Chambers
    0

    maybe you have an issue taking the value of your parameter and translation to a datetime datatype? Have you also coded around null values in the property?

    You could try debugging with 

    @(item.GetPropertyValue<DateTime>("dataArticolo").getType())

    If the datetime parser is struggling with translation of you property to a datetime then you could use

    DateTime.ParseExact(item.GetPropertyValue<DateTime>("dataArticolo"), "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture);

    where the second paramater is the format that you have for the format representation?

     

     

Please Sign in or register to post replies

Write your reply to:

Draft