Copied to clipboard

Flag this post as spam?

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


  • Ed 20 posts 40 karma points
    May 13, 2010 @ 20:18
    Ed
    0

    Formatting an Item to short date

    I have an item in a template of type date picker.  I want to format it as a short date but it's coming out as a long date with formatAsDate set to true.  I have the language of the site set to US English.  How do I do this?  Is there an Umbraco way, or do I need to wrap it in an ASP.Net tag?

    <p><umbraco:Item field="NewsDate" formatAsDate="true" runat="server"></umbraco:Item></p>

    Thanks.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 13, 2010 @ 20:25
    Sebastiaan Janssen
    0

    I usually do my date formatting through XSLT files. Using the XSLT extensions, it's very easy to format dates any way you'd like to. Check out the wiki article about it.

  • Ed 20 posts 40 karma points
    May 13, 2010 @ 20:50
    Ed
    0

    I would hope I don't have to change it to XSLT just to get the date formatted.  You shouldn't need code just to get an item on a page. 

    Is there a way to do this as I asked?

    Thanks.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 13, 2010 @ 21:04
    Jan Skovgaard
    0

    Hi Ed

    When you use <umbraco:item> the date field is formatted according to the culture on the server. In the dialogue it also says that beneath the field where you set the date-formatting: "Format the value as a date, or a date with time, accoring to the active culture."

    So I guess you should be able to change it by changing the way the server serves the date. Otherwise I would use XSLT like Sebastian is suggesting.

    /Jan

  • Jeff Grine 149 posts 189 karma points
    May 13, 2010 @ 21:05
    Jeff Grine
    0

    You can do inline xslt if that's more to your liking.

    http://umbraco.org/documentation/books/inline-xslt

  • Peter Dijksterhuis 1442 posts 1722 karma points
    May 13, 2010 @ 21:06
    Peter Dijksterhuis
    6

    You could try inline xslt:

    <umbraco:Item runat="server" field="NewsDate" xslt="umbraco.library:FormatDateTime({0},'dd-MM-yyyy')" />

    Peter

  • Ed 20 posts 40 karma points
    May 13, 2010 @ 23:55
    Ed
    0

    Don't confuse active server culture with the final date format.  3/22/2010 (short date), March 22, 2010 (long date) are both acceptable formats within the English US culture.

    In any case, the inline XSLT works for now.  It would be good to have more conrtrol over that than just formatAsDate="true" in the future.  Maybe just have the format string be a full up property instead of having to use XSLT.

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft