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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Time XSLT 1

Status
Not open for further replies.

CassidyHunt

IS-IT--Management
Jan 7, 2004
688
US
I know there is no direct way to format the date and time but I am having problems getting a template to work. Does anyone have a template that will do this?

The date looks like this:
2006-01-17T17:30:00.0000000-08:00

I would like it to look like this:
01/17/2006 5:30 pm

Thanks

Cassidy
 
I don't know magic built-in formula or template. I would just let the xsl do all the labour.
[tt]
[blue]<!-- variable name: given, alias x -->[/blue]
<xsl:variable name="given" select="'2006-01-17T17:30:00.0000000-08:00'" />
<xsl:variable name="y" select="substring-before($given,'T')" />
<xsl:variable name="CCYY" select="substring-before($y,'-')" />
<xsl:variable name="tmp" select="substring-after($y,'-')" />
<xsl:variable name="MM" select="substring-before($tmp,'-')" />
<xsl:variable name="DD" select="substring-after($tmp,'-')" />
<xsl:variable name="z" select="substring-after($given,'T')" />
<xsl:variable name="hh" select="substring-before($z,':')" />
<xsl:variable name="tmp2" select="substring-after($z,':')" />
<xsl:variable name="mm" select="substring-before($tmp2,':')" />
<xsl:variable name="tmp3" select="substring-after($tmp2,':')" />
<xsl:variable name="hh_norm">
<xsl:choose>
<xsl:when test="$hh &gt; 12">
<xsl:value-of select="$hh - 12" />
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$hh" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sffx">
<xsl:choose>
<xsl:when test="$hh &gt; 12">
<xsl:value-of select="'pm'" />
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="'am'" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="mm_norm" select="$mm" />
<xsl:variable name="result" select="concat($MM,'/',$DD,'/',$CCYY,' ',$hh_norm,':',$mm_norm,' ',$sffx)" />
[blue]<!-- display result here -->
<xsl:value-of select="$result" />[/blue]
[/tt]
You might have some format-number to do to improve fixed length integer according to need.
 
No magic needed. Your kong fu is strong enough to do what I need. Thank you very much.

Cassidy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top