Field formatting Options
tonyforgan
Posted: Monday, March 17, 2008 5:13:31 AM
Rank: Newbie

Joined: 3/17/2008
Posts: 4
Hi,

Wondering if it is possible to format a date type document property to be a different date format. When I use the following in my xslt
Code:

<xsl:value-of select="data [@alias = 'PositionCloseDate']"/>

I get a date format in timestamp format eg "2008-03-28T00:00:00". I would like to format it to be "dd/mm/yyyy".

Also, can someone suggest any good online xslt learning resources?

Thanks,

Tony Forgan
tonyforgan
Posted: Monday, March 17, 2008 6:10:07 AM
Rank: Newbie

Joined: 3/17/2008
Posts: 4
Sorry for the double post.

I have found a solution. I thought there would be a pre-built xslt function but there wasn't.

This is what I did - pretty basic but works for what I needed.

Code:

<!-- Converts 2008-03-21T00:00:00 to 21/03/2008 -->
    <xsl:template name="format-date">
        <xsl:param name="date" />
        <xsl:param name="format" select="0" />

        <xsl:if test="$date !=''">
            <xsl:variable name="year" select="substring($date, 1, 4)" />
            <xsl:variable name="month" select="substring($date, 6, 2)" />
            <xsl:variable name="day" select="substring($date, 9, 2)" />

            <xsl:value-of select="concat($day, '/', $month, '/', $year)" />
        </xsl:if>
        <xsl:if test="$date = ''">
            <xsl:text>Not stated</xsl:text>
        </xsl:if>
    </xsl:template>


Tony
neehouse
Posted: Monday, March 17, 2008 1:21:02 PM

Rank: Umbracoholic

Joined: 7/20/2006
Posts: 1,069
Location: Charleston, West Virginia, United States
Hi Tony,

There is the umbraco.library that has a function to format dates.

Code:

<xsl:value-of select="umbraco.library:FormatDate(data[@alias='dateField'],'dd/MM/yyyy')"/>

or

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




• 2007/2008 MVP • 2008/2009 MVP • Core Developer • Certified Professional Level I & II •
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.