Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Correct syntax for date

Status
Not open for further replies.

bjmurph

Programmer
Mar 2, 2007
4
CA
Hi there, I'm trying to find a way to ensure a date is in a specific format, however I'm struggling. I want it to be in the format yyyy-mm-dd hh:mm:ss, and if it's not in that format I want to output something generic (for instance, 2000-01-01 00:00:00). I'm trying to do this using xslt. This is my current code, which is just an example I'm using to figure it out:

<xsl:variable name="varfulldate"><xsl:value-of select="fulldate"/></xsl:variable>

<xsl:choose>
<xsl:when test='$varfulldate=2'>
<td><xsl:value-of select="fulldate"/></td>
</xsl:when>
<xsl:eek:therwise>
<td>2000-01-01 00:00:00</td>
</xsl:eek:therwise>
</xsl:choose>

This works, however I obvoiusly don't want to test if it's equal to '2'. I want to somehow test to ensure it's in the proper format, and if not I want to through the whole value away and use 2000-01-01 00:00:00. Does anyone know how to do this?
 
Thanks opengavel, however I'm fairly new to xml/xslt developing and that method doesn't seem to be working for me. If I put the first example in from number 12 (i.e. not the custom function), I get the following error in firefox:

Error during XSLT transformation: An XPath expression was expected to return a NodeSet.

If I change the line (only because I'm guessing that's the problem line):
<xsl:for-each select="$dates/DATE">
To:
<xsl:for-each select="myactualpath/fulldate">

I get the following error:
Error during XSLT transformation: An unknown XPath extension function was called.
 
Note that 5 figures for the year is legal in XML.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top