Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chau 66 posts 97 karma points
    Oct 05, 2009 @ 09:48
    Chau
    0

    date format

    According to http://our.umbraco.org/wiki/reference/umbracolibrary/formatdatetime I should be getting a single or doube digit date such as 1, 2, ..., 30, 31.

    Instead it is giving me something more like 11/1/2009. Here is the code snippet:

            <xsl:value-of select="umbraco.library:FormatDateTime(data [@alias='eventDate'], 'd')"/>
            <xsl:variable name="dateNum" select="umbraco.library:FormatDateTime(data [@alias='eventDate'], 'dd')"/>
            <xsl:choose>
          <xsl:when test='dateNum=1 or 21 or 31'>
             <xsl:text>st</xsl:text>
          </xsl:when>
          <xsl:when test='dateNum=2 or 22'>
             <xsl:text>nd</xsl:text>
          </xsl:when>
          <xsl:otherwise>
             <xsl:text>th</xsl:text>
          </xsl:otherwise>
            </xsl:choose>

    I can substitute d for dd and get 01, 02, ..., 30, 31, but that isn't the format that I want. I'm pretty sure that I need to use the MSDN custom date properties but how do I get it to toggle over? Thanks.

  • Chau 66 posts 97 karma points
    Oct 05, 2009 @ 09:49
    Chau
    0

    Ahhh, it forces it into a custom date if you add a white space. In effect, 'd' becomes ' d' and it goes into the custom date format.

  • Chau 66 posts 97 karma points
    Oct 05, 2009 @ 18:52
    Chau
    0

    So I found that I had to write this code like this to get it to work:

                          <xsl:when test="$dateNum=1">
                            <xsl:text>st</xsl:text>
                          </xsl:when>
                          <xsl:when test="$dateNum=21">
                            <xsl:text>st</xsl:text>
                          </xsl:when>
                          <xsl:when test="$dateNum=31">
                            <xsl:text>st</xsl:text>
                          </xsl:when>
                          <xsl:when test="$dateNum=2">
                            <xsl:text>nd</xsl:text>
                          </xsl:when>
                          <xsl:when test="$dateNum=22">
                            <xsl:text>nd</xsl:text>
                          </xsl:when>

    How come writing it like this doesn't work:

                          <xsl:when test="$dateNum=1 or 21 or 31">
                            <xsl:text>st</xsl:text>
                          </xsl:when>

                          <xsl:when test="$dateNum=2 or 22">
                            <xsl:text>nd</xsl:text>
                          </xsl:when>

    So confused???!!!

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Oct 05, 2009 @ 20:44
    Douglas Robar
    1

    You're close!

    Try this...

    <xsl:choose>
        <xsl:when test="$dateNum=1 or $dateNum=21 or $dateNume=31">
            <xsl:text>st</xsl:text>
        </xsl:when>
        <xsl:when test="$dateNum=2 or $dateNum=22">
            <xsl:text>nd</xsl:text>
        </xsl:when>
        <xsl:when test="$dateNume=3 or $dateNume=23">
            <xsl:text>rd</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:text>th</xsl:text>
        </xsl:otherwise>
    </xsl:choose>

    cheers,

    doug.

  • Chau 66 posts 97 karma points
    Oct 06, 2009 @ 03:24
    Chau
    0

    Thanks Doug! This forum beats beating my head on my table anyday...

Please Sign in or register to post replies

Write your reply to:

Draft