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 got the following formate returned from "Write" in english:

<write>09/12/2012</write>

I parse that with the following line and return a german format: 12. Sep.

<xsl:value-of select="ddwrt:FormatDateTime(string(write),1031, 'd. MMM.')"/>

If i now change the regional settings to german i get the following result in the SCR

<write>12.09.2012</write>

but the german format that comes back is 9. Dez (9.12.2012) ...

How can i fix that?

share|improve this question
    
What is the unformatted date after changing the regional settings to german? This function relies on ISO8601 format yyyy-mm-ddThh:mm:ssZ. –  Hugh Wood Sep 12 '12 at 8:47
    
As i wrote, the date changes from 09/12/2012 to 12.09.2012 -> Its already regionalformated and no raw iso –  fr34kyn01535 Sep 12 '12 at 11:24
    
Okay I understand, try this solution: social.technet.microsoft.com/Forums/is/… –  Hugh Wood Sep 12 '12 at 12:15
    
What a bullsh*t... Why does it only recognise english time format? It has '.''s .. How does it interpret 12.09.2012 to 12/09/2012 ?! WHY!? ... Well done MS .. What happens now if someone changes the format back to english and i do substring? I would have a wrong date again.. I dont wanna do this for every possible region. –  fr34kyn01535 Sep 14 '12 at 11:44
    
Nice fix, please post your code, as the solution so others can benefit. –  Hugh Wood Nov 6 '12 at 8:44
add comment

1 Answer 1

up vote 0 down vote accepted

Fixed it with recognising if time has dots.If so then just took the values of dd, mm and yyyy and rebuilded the string then ..

<xsl:variable name="date">
    <xsl:call-template name="TransformDate">
        <xsl:with-param name="String" select="write"/>
    </xsl:call-template>
</xsl:variable>

<b class="smalldate">
    <xsl:value-of select="ddwrt:FormatDateTime(string($date),1031, 'd. MMM.')"/>
</b>

<xsl:template name="TransformDate">
    <xsl:param name="String"/>
    <xsl:choose>
      <xsl:when test="contains($String, '.')">
        <xsl:value-of select="substring($String, 4,2)"/>
        <xsl:value-of select="'/'"/>
        <xsl:value-of select="substring($String, 1,2)"/>
        <xsl:value-of select="'/'"/>
        <xsl:value-of select="substring($String, 7,4)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$String"/>
      </xsl:otherwise>
    </xsl:choose>
</xsl:template>

Does something like "06. Nov." no matter if region was set to english, or german (and i guess all the other countries with dateformat dd.mm.yyyy). Now you can easily switch to another dateformat (thanks to ddwrt).

share|improve this answer
add comment

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.