Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Sep 12, 2013 @ 16:15
    Anthony Candaele
    0

    cannot format DateTime using umbraco.library.FormatDateTime()

    Hi,

    Has the FormatDateTime() method changed in Umbrac v6 ?

    this used to work:

    umbraco.library.FormatDateTime(article.GetPropertyValue("mediaArticlePublicationDate"), "dd/MM/yyyy") 

    now I'm getting this error message in VS

    Error 226 The best overloaded method match for 'umbraco.library.FormatDateTime(string, string)' has some invalid arguments c:\Repos\cjs_cms\Views\MacroPartials\MediaArticleList.cshtml 36 21 C:\Repos\cjs_cms\

    Thanks for your help,
    Anthony
  • Anthony Candaele 1197 posts 2049 karma points
    Sep 12, 2013 @ 16:38
    Anthony Candaele
    0

    found out that this works:

    @if (article.HasValue("mediaArticlePublicationDate"))

                    {

                        string date = article.GetPropertyValue("mediaArticlePublicationDate").ToString();

                        @umbraco.library.FormatDateTime(date, "dd/MM/yyyy");                             

                    }

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Sep 18, 2013 @ 11:51
    Ali Sheikh Taheri
    101

    Hi Anthony I would use something like this if you are using umbraco 6 with strongly typed.

    @if(article.HasValue("mediaArticlePublicationDate")
    {
        @(article.GetPropertyValue<DateTime>("mediaArticlePublicationDate").ToString("dd/MM/yyyy"))
    }
    
  • Anthony Candaele 1197 posts 2049 karma points
    Sep 19, 2013 @ 09:04
    Anthony Candaele
    0

    Hi Ali,

    Thanks for the tip. I tried this:

    <dd><time datetime="@Model.Content.GetPropertyValue<DateTime>("mediaArticlePublicationDate").ToString("dd/MM/yyyy")"></time>...</dd>

    though the compiler is complaining:

     

    Error1Cannot convert method group 'GetPropertyValue' to non-delegate type 'object'. Did you intend to invoke the method?

    Any idea?
    thanks for your help,
    Anthony
  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Sep 19, 2013 @ 10:56
    Ali Sheikh Taheri
    1

    this will sort it out:

    when you use <> within the markup you need to wrap razor with ()

    <dd>
        <time datetime="@(Model.Content.GetPropertyValue<DateTime>("mediaArticlePublicationDate").ToString("dd/MM/yyyy"))"></time>
    </dd>
    
  • Anthony Candaele 1197 posts 2049 karma points
    Sep 19, 2013 @ 11:25
    Anthony Candaele
    0

    oh I see. Thanks a lot, it's working now : )

Please Sign in or register to post replies

Write your reply to:

Draft