This project is read-only.

Date Part Conversions

Sep 15, 2010 at 4:58 PM
Example:

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

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

Coordinator
Sep 16, 2010 at 12:34 PM
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 12:49 PM

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

Coordinator
Sep 16, 2010 at 12:55 PM
Give it a try; it ought to work. See: http://sympmarc.com/2009/04/21/displaying-columns-in-a-crosslist-dvwp/ M.