473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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.
Nov 1 '07 #1
3 6523
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.
Nov 5 '07 #2
jkmyoung
2,057 Expert 2GB
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>18102007</date>
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="month" select="substring(date, 1, 2)"/>
  2. <!-- find date -->
  3. <xsl:choose>
  4.   <xsl:when test="$month != '02'">
  5.     <xsl:value-of select="document('')//day[$month = @month]"/> 
  6.   </xsl:when>
  7.   <xsl:otherwise>
  8.     <xsl:variable name="year" select="substring(date, 5, 4)"/>
  9.     <xsl:choose>
  10.       <xsl:when test="($year mod 4 = 0) and ($year mod 100 != 0 or $year mod 400 = 0)">29</xsl:when>
  11.       <xsl:otherwise>28</xsl:otherwise>
  12.     </xsl:choose>
  13.   </xsl:otherwise>
  14. <xsl:value-of select="substring(date, 3, 6)"/> <!-- output rest of date -->
  15.  
  16. ... Put this at end of stylesheet, just inside stylesheet node.
  17. ...
  18. <my:monthdays xmlns:my="internal">
  19.   <day month="01">31</day>
  20.   <day month="02">28</day>
  21.   <day month="03">31</day>
  22.   <day month="04">30</day>
  23.   <day month="05">31</day>
  24.   <day month="06">30</day>
  25.   <day month="07">31</day>
  26.   <day month="08">31</day>
  27.   <day month="09">30</day>
  28.   <day month="10">31</day>
  29.   <day month="11">30</day>
  30.   <day month="12">31</day>
  31. </my:monthdays/>
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.
Nov 5 '07 #3
thanks a lot jkmyoung. This works great.
Nov 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Solomon Grundy | last post by:
Select trunc(sysdate,'MM') from dual of course gives me the first day of the month, may I ask what the query is to find the first saturday of the month?
13
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not...
3
by: Gol Yass | last post by:
Dear Newsgroup, Is there a function in Access XP to take a date or month , and return the last day in that month? Ex: the last day in september is 30 or the last day in May is 31 . Thank...
4
by: laredotornado | last post by:
Hi, Using PHP 4, if I have a date, what is a function I could use to give me a date that represents the first day of that month? For example, if my date were "3/19/2006 8:00", I would want my...
2
by: planetthoughtful | last post by:
Hi All, I'm building some reports in Acc97 and using a custom calendar form to allow users to pick dates with which to report. I'm wondering if there's an easy way in code to be able to...
10
by: kyosohma | last post by:
Hi, I am working on a timesheet application in which I need to to find the first pay period in a month that is entirely contained in that month to calculate vacation time. Below are some example...
0
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and...
1
by: Presto | last post by:
I have two date fields. PaymentDate - is set to default to today : =Date() MeetingDate - is going to find the next meeting date after the PaymentDate So using April as an example: If...
2
livid86
by: livid86 | last post by:
Hey guys, I am a little stuck. What i need to do is write a script that will find four things. - This week - Last Week - This month - Last Month What i want it to do is the user can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.