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
    Jan 10, 2011 @ 16:20
    Anthony Candaele
    0

    how to formate date with xslt

    Hi,

    I'm implementing news functionality for a website.

    In my xslt file, the date is accessed like this:

    <td class="date"><xsl:value-of select="newsDate"/></td>

    This works great but the date rendered on the page is a full date with time part, like this:

    2011-01-10T00:00:00


    I don't need the time part. Does someone know how I can read out the date without the time part, like this:

    2011-01-10

    Thanks for your help,

    Anthony Candaele
    Belgium

  • Comment author was deleted

    Jan 10, 2011 @ 16:22

    Hi Anthony

    You'll need to use an umbraco.library function called FormatDateTime

    Example

    umbraco.library:FormatDateTim($currentPage/@createdate,'dddd dd MMMM yyyy')

     

  • Comment author was deleted

    Jan 10, 2011 @ 16:22

    umbraco.library:FormatDateTime($currentPage/@createdate,'dddd dd MMMM yyyy') that is

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 10, 2011 @ 16:23
    Kim Andersen
    0

    Hi Anthony.

    You can try out this:

    <xsl:value-of select="umbraco.library:FormatDateTime(newsDate,'yyyy-MM-dd')"/>

    /Kim A

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 10, 2011 @ 16:32
    Anthony Candaele
    0

    Thanks Tim and Kim, I should have a little more confidence in myself, I tried out an Umbraco library function and solved it like this:

    <td class="date"><xsl:value-of select="Exslt.ExsltDatesAndTimes:date(newsDate)"/></td>

    this gives the following result:

    2011-01-10

    But maybe this format is better:

    10/01/2011

    so I'll use this Umbraco library function suggested by Kim:

    <xsl:value-of select="umbraco.library:FormatDateTime(newsDate,'dd-mm-yyyy')"/>

    hmmm, curious result, I get:

    10-00-2010

    :)

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 10, 2011 @ 16:34
    Anthony Candaele
    0

    ok, should have been:

    <xsl:value-of select="umbraco.library:FormatDateTime(newsDate,'dd-MM-yyyy')"/>

    Thanks Kim and Tim for helping me out!

    Anthony

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 10, 2011 @ 17:56
    Kim Andersen
    0

    No problemo Anthony.

    If you want to know more about formatting dates using the FormatDateTime extension, I'd suggest that you read this wiki. There are some good examples, and explanations of how you can achieve the result you want.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft