14

I have a date(string) value in an XML file in this format:

Tue Apr 17 03:12:47 IST 2012

I want to use XSL transformation to convert the string/date into this format:

4/17/2012 03:12:47 AM

How can I do that in my XSL transform?

2
  • Which xslt version (1.0, 2.0) can/would you use? Commented Jun 3, 2013 at 8:05
  • I can use both in fact. Would prefer 1.0. Commented Jun 3, 2013 at 8:08

1 Answer 1

22

If you are using

But my suggestion is to

Have a standard XSD datetime format on XML, on the code-behind (that is, on rendering time) you can format as you like.

Update:

Always XML to process through XSLT, dates should be in standard XSD format. Currently your input is not in standard format so that it throws error.

Example:

<xsl:variable name="dt" as="xs:dateTime" select="xs:dateTime('2012-10-21T22:10:15')"/>
<xsl:value-of select="format-dateTime($dt, '[Y0001]/[M01]/[D01]')"/>

OUTPUT:

2012/10/21

Sign up to request clarification or add additional context in comments.

6 Comments

I am using the format-dateTime function (2.0) and its giving me this error: 'Invalid dateTime value "Tue Apr 17 03:12:47 IST 2012" (Non-numeric year component)'
@RohitGupta: Show your xslt
<Date><xsl:value-of select="format-dateTime(CreatedDate, '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')" /></Date>
@SivaCharan I got an Error during XSLT transformation: An unknown XPath extension function was called. exaption, may be you know where is the problem
@ArturKeyan: Its better you can post a new question with detailed error message and your XSLT. So that I can help you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.