Copied to clipboard

Flag this post as spam?

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


  • Connie DeCinko 95 posts 248 karma points
    May 20, 2019 @ 18:55
    Connie DeCinko
    0

    Format date of Nested Content list item

    How can I change the date format for an item in a Nested Content list in the back office? By default it shows year first. I want dd/mm/yyyy.

    enter image description here

  • Markus Johansson 1936 posts 5864 karma points MVP 2x c-trib
    May 20, 2019 @ 19:52
    Markus Johansson
    0

    You should be able to use a angular filter in the label, something like this

    {{createDate | date:'yyyy-MM-dd HH:mm:ss Z'}}

    Edit: Or... maybe not. Some dates are returned as strings from the Umbraco APIs... then you would first have to convert the string to a JS-date and then format it... maybe could be done using momentjs..

    Something like this

    {{moment(createDate).format("MMM Do YY")}}

    I’m not sure that this would work... and you might have to include momentsjs introt he backoffice using a package.manifest-file

  • Connie DeCinko 95 posts 248 karma points
    May 20, 2019 @ 20:51
    Connie DeCinko
    0

    Yeah, by itself, that does not return anything. Seems like this ability should be out of the box.

  • Markus Johansson 1936 posts 5864 karma points MVP 2x c-trib
    May 21, 2019 @ 06:49
    Markus Johansson
    0

    Hi!

    I just had a closer look at this since I created my example from my phone without access to any computer to test with.

    First of all, Nested Content does not store the create date, it just stores a minimal amount of data for the created item

    This is from the umbraco cache-file in the app_data folder:

    <nSTest><![CDATA[
    [{ 
     "key":"76ca0088-6841-42f8-836d-5ff25afa5527",
     "name":"Item 1 Hallo",
     "ncContentTypeAlias":"test",
     "information":"Hallo"
     "eventDate": "2019-05-26 08:31:08"
      },
     {
      "key":"2f398518-fac2-4d8b-ad13-1c256765ed1d",
      "name":"Item 2 Test",
      "ncContentTypeAlias":"test",
       "information":"Mamma mia"
      "eventDate": "2019-05-23 08:31:08"
    }]
    ]]>
    </nSTest>
    

    So it only stores some data about the documentype, a key and the generic properties, not a standard property like "create date". Any way. As you can see the eventDate (or any date) is stored as a string formatted like in your screenshot.

    I tested the example code that I was proposing and as you say it does not render anything, and it does not throw any errors.

    {{moment(eventDate).format('YYYY')}}
    

    And since the date is just a string, the standard filter in AngularJS will not work either.

    {{eventDate | date:'yyyy-MM-dd HH:mm:ss Z'}}
    

    I guess that if you really need to format the date you could try to create your own AngularJS filter that’s using MomentJs to first convert the string to a date and then formats the date from there. Maybe something like this:

    https://gist.github.com/cmmartin/341b017194bac09ffa1a

    You would then need to include this filter in a js-file that you reference in a package.manifest file to the the Umbraco backoffice to load your filter.

    I do see that this is a complicated solution to a simple problem but there is no built in way to format the date as far as I know.

    Hope you find your way around this!

  • Kristian Ravnevand 94 posts 214 karma points
    May 26, 2020 @ 08:32
    Kristian Ravnevand
    2

    I think Erik-Jan's answear at this page https://our.umbraco.com/forum/using-umbraco-and-getting-started/100308-nested-content-template solves this problem in Umbraco 8

    {{dateUntill| momentDateTimeZone:"YYYY-MM-DD"}}

Please Sign in or register to post replies

Write your reply to:

Draft