Date Part Conversions

Sep 15, 2010 at 3:58 PM

<xsl:call-template name="GetDatePart">
  <xsl:with-param name="dtString" select="$Today" />
  <xsl:with-param name="fmtString" />

<xsl:template name="GetDatePart">
  <xsl:param name="dtString" />
  <xsl:param name="fmtString"  />
    <xsl:when test="$fmtString = 'dd'"> 
      <xsl:value-of select="substring-before(ddwrt:FormatDate($dtString,2057,5),'/'))" />
    <xsl:when test="$fmtString = 'd'"> 
      <xsl:value-of select="substring-before(ddwrt:FormatDate($dtString,3076,5),'/'))" />
    <xsl:when test="$fmtString = 'mm'"> 
      <xsl:value-of select="substring-before(ddwrt:FormatDate($dtString,9225,5),'/'))" />
    <xsl:when test="$fmtString = 'm'"> 
      <xsl:value-of select="substring-before(ddwrt:FormatDate($dtString,1033,5),'/'))" />
    <xsl:when test="$fmtString = 'yyyy'"> 
      <xsl:value-of select="substring-before(ddwrt:FormatDate($dtString,1078,5),'/'))" />
      <xsl:value-of select="substring-before(ddwrt:FormatDate($dtString,1033,3),','))" /> // defaults to the name of the day of the week in English

Sep 16, 2010 at 11:34 AM
Jim Bob: I'm curious why you wouldn't do this type of date reformatting with the format mask directly in ddwrt:FormatDate. For example: ddwrt:FormatDate($Today, 1033, 'yyyy') M.
Sep 16, 2010 at 11:49 AM

Hmmm... I was having trouble with the FormatDate and thought it wouldn't accept the mask. Maybe my issue was something different.

Sep 16, 2010 at 11:55 AM
Give it a try; it ought to work. See: M.