XSL:Sort by Date Time

If you are stuck trying to sort XML date by date/time then this snippet of code may help you. Been stuck in head first into some XSL scripting, so learning at quite a rate.

<xsl:sort select=”ddwrt:FormatDateTime(@DateTimeField, number($lcid), ‘yyyyMMddHHmm’)” />

In the above line, @DateTimeField is the name of the field to sort, $lcid is your locale number.

By doing this, the data is then sorted as a number, in ascending date order, without having to change the underlying date. By changing the format at the end you could also quickly sort just by time or date, depending on the format of the source data.

Happy sorting!

8 people found this post useful.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.