Azure / Office 365 / SharePoint Development / Search

Bug With SharePoint 2010 XSLT DateFormat Function

on Jul 29, 2011 by Elio Struyf with 4 comments

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/2011 8-June-2011
2/3/2011 2-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/2011 19-August-2011
2/30/2011 30-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)

English (United States) Regional Setting

English (United States) Regional Setting

English date format converted to Dutch date format

English date format converted to Dutch date format

Dutch (Belgium)

Dutch (Belgium) Regional Setting

Dutch (Belgium) Regional Setting

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

Call the XSL template

Result

XSL Template Result

XSL Template Result

XSLT Month Options

MM - Number notation

MM - Number notation

MMM - Short Name Format

MMM - Short Name Format

MMMM - Full Name Format

MMMM - Full Name Format

Article comments

  • Ponni

    Execellent …! Highly useful post…..thanks

    • estruyf

      Ponni,

      Thank you for your comment!

  • priya

    Hi can u please send me the date format for ” Monday 27th Febrarury 2012″?

    • estruyf

      Priya,

      You could do the following for your date notation:
      To show the number suffixes, you will need to create an function/template for that (adding a suffix to a number).

      Regards,
      EStruyf