0

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?

5
  • 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
    Commented Sep 12, 2012 at 8:47
  • As i wrote, the date changes from 09/12/2012 to 12.09.2012 -> Its already regionalformated and no raw iso Commented Sep 12, 2012 at 11:24
  • Okay I understand, try this solution: social.technet.microsoft.com/Forums/is/…
    – Hugh Wood
    Commented Sep 12, 2012 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. Commented Sep 14, 2012 at 11:44
  • Nice fix, please post your code, as the solution so others can benefit.
    – Hugh Wood
    Commented Nov 6, 2012 at 8:44

1 Answer 1

0

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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