Quantcast
Channel: Formatting date in xslt - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Formatting date in xslt

$
0
0

I'm trying to format a certain date format in xslt. This is the format:

2012-7-19

I'd like to convert this to a numerical value in xslt for sorting, so that the above would become:

20120719

The problem is that single months/days don't have a 0 in front of them. So I need to somehow add that in front of single digit months/days, but not in front of months/days that have two digits. Does anyone know how I can do this?

I have this so far:

<xsl:value-of select="concat(    substring(substring-after(substring-after(./AirDate, '/'),'/'),0,5),    substring(substring-after(./AirDate, '/'), 0, 3),    substring-before(./AirDate, '/'))"/>

but that occasionally throws in a / for single digit days, and doesn't put a 0 in front of single digit months/days

I don't have the ability to change the data source before passing it to the xslt, and I have to use xslt version 1.0.


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>