Finding last day of the month

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sudesna
    New Member
    • Nov 2007
    • 9

    Finding last day of the month

    Hi,
    I am currently writing a stylesheet. The problem is, I have been given a date in the format DDMMYYYY(for example: 18102007). from this date I have to calculate and display the last day of the month. The given date is a variable and not a fixed date.

    Please help me in solving this issue.
  • Sudesna
    New Member
    • Nov 2007
    • 9

    #2
    Finding last day of the month

    hi,
    I am working with XSLT 2.0. I have a date format DDMMYYYY(for e.g. 18102007). This date format in xml, is a variable. From this variable I need to calculate the last day of the month and display it. PLease help me.

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      Originally posted by Sudesna
      hi,
      I am working with XSLT 2.0. I have a date format DDMMYYYY(for e.g. 18102007). This date format in xml, is a variable. From this variable I need to calculate the last day of the month and display it. PLease help me.
      say string is in element date:
      <date>1810200 7</date>
      [code=xml]
      <xsl:variable name="month" select="substri ng(date, 1, 2)"/>
      <!-- find date -->
      <xsl:choose>
      <xsl:when test="$month != '02'">
      <xsl:value-of select="documen t('')//day[$month = @month]"/>
      </xsl:when>
      <xsl:otherwis e>
      <xsl:variable name="year" select="substri ng(date, 5, 4)"/>
      <xsl:choose>
      <xsl:when test="($year mod 4 = 0) and ($year mod 100 != 0 or $year mod 400 = 0)">29</xsl:when>
      <xsl:otherwise> 28</xsl:otherwise>
      </xsl:choose>
      </xsl:otherwise>
      <xsl:value-of select="substri ng(date, 3, 6)"/> <!-- output rest of date -->

      ... Put this at end of stylesheet, just inside stylesheet node.
      ...
      <my:monthdays xmlns:my="inter nal">
      <day month="01">31</day>
      <day month="02">28</day>
      <day month="03">31</day>
      <day month="04">30</day>
      <day month="05">31</day>
      <day month="06">30</day>
      <day month="07">31</day>
      <day month="08">31</day>
      <day month="09">30</day>
      <day month="10">31</day>
      <day month="11">30</day>
      <day month="12">31</day>
      </my:monthdays/>[/code]

      Also, merged your 2 threads.

      Didn't realize your date was in a variable, so just do a search and replace "date" with your variable name.
      Last edited by jkmyoung; Nov 5 '07, 07:29 PM. Reason: More comments after merge.

      Comment

      • Sudesna
        New Member
        • Nov 2007
        • 9

        #4
        thanks a lot jkmyoung. This works great.

        Comment

        Working...