Alert This post is over a year old, some of this information may be out of date.

Bug With SharePoint 2010 XSLT DateFormat Function

Yesterday I found out that there is a problem/bug using the XSLT ddwrt:DateFormat function. The problem/bug occurs when the regional settings is not set to English (United States).

When a day got the value between 1 and 12, the ddwrt:DateFormat function will recognize this as the month. The month value will be used as the day.

So if the day value is less than 13, you get the following problem:

**US Date Format****ddwrt:DateFormatTime(date, 1043, 'dd-MMMM-yyyy')**
8/6/20118-June-2011
2/3/20112-March-2011
When the day value is larger than 13, you get the correct formatting:

So if the day value is less than 13, you get the following problem:

**US Date Format****ddwrt:DateFormatTime(date, 1043, 'dd-MMMM-yyyy')**
8/19/201119-August-2011
2/30/201130-February-2011
I did not notice it in the beginning, because my settings are always set to English (United States) on my development server. When I implemented the XSLT stylesheet on a different environment, where the regional settings were set to **Dutch (Belgium)**, some of dates were incorrectly formatted.

English (United States)

Show image English (United States) Regional Setting
English (United States) Regional Setting
Show image English date format converted to Dutch date format
English date format converted to Dutch date format

Dutch (Belgium)

Show image Dutch (Belgium) Regional Setting
Dutch (Belgium) Regional Setting
Show image Conversion problem with the Dutch date format
Conversion problem with the Dutch date format

Solution

After some research and testing without result, I did some googling and found a post from someone who had the same problem. The blog post can be found here. In this blog post he included a custom XSL template to format the date.

I have created my own version of his XSL template to format the date in Dutch date format.

XSL Template

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<xsl:template name="FormatDutchDate">
	<!-- Template Parameters -->
	<xsl:param name="dateValue" />
	<xsl:param name="monthFormat" /> 

	<!-- Split Date -->
	<xsl:variable name="day" select="substring-before($dateValue, '/')" />
	<xsl:variable name="month" select="substring(substring-after($dateValue, '/'), 1, 2)" />
	<xsl:variable name="year" select="substring(substring-after(substring-after($dateValue, '/'), '/'), 1, 4)" />

	<!-- Create US Date Format -->
	<xsl:variable name="USDate">
		<xsl:value-of select="$month" />/<xsl:value-of select="$day" />/<xsl:value-of select="$year" />
	</xsl:variable>

	<!-- Month Notation -->
	<xsl:variable name="monthString">                                                
		<xsl:choose>
			<xsl:when test="$monthFormat='MM'">
				<xsl:value-of select="$month" />
			</xsl:when>
			<xsl:when test="$monthFormat='MMM'">
				<xsl:value-of select="ddwrt:FormatDateTime($USDate, 1043, 'MMM')" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="ddwrt:FormatDateTime($USDate, 1043, 'MMMM')" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<!-- Create Date -->
	<xsl:choose>
	<xsl:when test="string-length($day) = 1">0</xsl:when>
	</xsl:choose>
	<xsl:value-of select="$day" />-<xsl:value-of select="$monthString" />-<xsl:value-of select="$year" />
</xsl:template>

Call the XSL template

1
2
3
4
<xsl:call-template name="FormatDutchDate">
  <xsl:with-param name="dateValue" select="@Expires" />
  <xsl:with-param name="monthFormat">MMM</xsl:with-param>
</xsl:call-template>

Result

Show image XSL Template Result
XSL Template Result

XSLT Month Options

1
<xsl:with-param name="monthFormat">MM</xsl:with-param>
Show image MM - Number notation
MM - Number notation
1
<xsl:with-param name="monthFormat">MMM</xsl:with-param>
Show image MMM - Short Name Format
MMM - Short Name Format
1
<xsl:with-param name="monthFormat">MMMM</xsl:with-param>
Show image MMMM - Full Name Format
MMMM - Full Name Format

Comments

Back to top