Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using a custom XSLT file to format the oob created column to not show time, only date.

I have this code :

  <xsl:template name="FieldRef_ValueOf.Created"
                match="FieldRef[@Name='Created']"
                mode="DateTime_body">
    <xsl:param name="thisNode"
               select="." />
    <xsl:value-of select="ddwrt:FormatDate($thisNode/@Created,1036,1)" />
  </xsl:template>

As you can see, I specify the 1036 (French) culture.

However, this produces the date in the wrong format : month/day/year (01/10/2012), instead of the expected day/month/year (10/01/2012).

Why does this method behaves like this? How can I correct this?

FYI, if I set up the 1033 culture, the date is now in the correct French format.

In fact, the day and month seems to be swapped.

[edit] I found a KB entry at Microsoft. The XsltListViewWebPart seems to buggy. Unfortunately, the suggested workaround are not very satisfying.

share|improve this question

2 Answers 2

The problem is that $thisNode/@Created is represented in french format (10/02/2013 for Feb 10th, 2013), but the FormatDateTime() function expects it to be the other way round (i.e. understands October 2nd). This is in particular annoying, because it tries to tolerate "obvious errors" like 31/12/2013, which becomes correctly Dec 31st (which ShPt beleives is 12/31/2013) on any system.

Thus, {{{ FormatDateTime('10/02/2013', nls, 'dd+MM') = '02+10' FormatDateTime('31/12/2013', nls, 'dd+MM') = '31+12' }}} whatever nls is (1033 or 1036 or ...), but only on french (or german, or slovene, ...) systems, but not on US-installed ShPt servers (with SPWeb's locale 1033).

Got it?

share|improve this answer

Haven't tested, but this might work:

ddwrt:FormatDateTime(string($thisNode/@Created), 1036, 'ddMMyyyy')

Edit

This worked for me:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">
    <xsl:include href="/_layouts/xsl/main.xsl"/>
    <xsl:template name="FieldRef_DateTime_body.Created" match="FieldRef[@Name='Created']"  mode="DateTime_body" ddwrt:dvt_mode="body">
        <xsl:param name="thisNode" select="."/>
            <xsl:value-of select="ddwrt:FormatDateTime(string($thisNode/@Created), 1036, 'dd/MM/yyyy')" />
    </xsl:template>
</xsl:stylesheet>
share|improve this answer
    
Unfortunately, this throws a System.OverflowException: Arithmetic operation resulted in an overflow. –  Steve B Jan 10 '13 at 12:09
    
this will works if your SPWeb's locale is 1033. But if the site is not english (mine is 1036, French), the formatdate and the xsltlistviewwebpart won't use the same locale (one of them is 1033, the other is 1036). That will cause a double swap of my dates' component. Take a look in the KB for explanation. –  Steve B Jan 11 '13 at 8:45
    
Strange, my site is 1044 (norwegian) –  Anders Aune Jan 11 '13 at 8:56
    
maybe the behavior is different from one locale to another, depending on the order of components. –  Steve B Jan 11 '13 at 8:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.