Tell me more ×
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

1 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 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 at 8:45
Strange, my site is 1044 (norwegian) – Anders Aune Jan 11 at 8:56
maybe the behavior is different from one locale to another, depending on the order of components. – Steve B Jan 11 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.