hulda.rachel
hulda.rachel

Reputation: 23

Date format in XSLT

I have the date format coming as "19 May 2016", I want to write a condition if it's in that format , it should be converted as "19-May-16". How do i do it in xslt.Would appreciate an quick answer.

Upvotes: 1

Views: 77

Answers (2)

michael.hor257k
michael.hor257k

Reputation: 117140

Actually, this is very easy to do in XSLT - although a bit verbose:

<xsl:value-of select="substring-before(date, ' ')"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring-before(substring-after(date, ' '), ' ')"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring(substring-after(substring-after(date, ' '), ' '), 3, 2)"/>

Upvotes: 2

Chris Summers
Chris Summers

Reputation: 10163

You will need an extension method for this, as doing it in XSLT is really hard. It is a long time since I used the XSLT mediator(s), and you don't state if you are using the one from the TBB Site, or the out of thebox one that comes with SDL Tridion 2013 and higher

Take a look at https://www.sdltridionworld.com/community/extension_overview/xsltmediator.aspx and search for Date

and http://docs.sdl.com/LiveContent/content/en-US/SDL_Tridion_2013/concept_8E74450486DE4950B81B3D83ACDDF5FA

The function to do this inside SDL is <xsl:value-of select="mediator:GetFormattedDate('2012-10-08T06:30:00', 'MMMM dd, yyyy')" />

Upvotes: 1

Related Questions