Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 12th, 2012, 04:54 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default Subtracting end date - inital date but count only week days not Saturdays and Sundays

Hi,

Is possible to subtract the end date - start date and get the number of days but without weekends?

So, if I am on Friday and my end date is the following Monday then I should get 1 instead of 3.

<root>
<StartDate>9 July 2012</StartDate>
<StartDate>24 September 2016</StartDate>
<root>

Cheers

C



asdfasdf
Reply With Quote
  #2 (permalink)  
Old July 12th, 2012, 05:24 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First write a function to compute day of week dow() for a given date: subtract a well-known Sunday from the date, divide by the duration PT1D, then take the result modulo 7.

Now subtract the two dates, divide by the duration PT1D to get an integer number of days D, and then take W= (D div 7)*5 to get the number of weekdays in whole weeks. Then work out how many extra days you need to add based on the day-of-week of the two days: if you know that both are weekdays, this is dow(END)-dow(START) if positive, otherwise 7-(dow(START)-dow(END)).
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
pallone (July 13th, 2012)
  #3 (permalink)  
Old July 13th, 2012, 07:56 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Thanks very much for your reply.

I am trying to learn now to do this in XSLT 1.0. I know your explanation was very thorough.

Could you please kindly show us how to create this method. I really would like to learn how to do this but I guess I am not a guru like you guys (i.e. not as clever as you guys).

Cheers

C
Reply With Quote
  #4 (permalink)  
Old July 13th, 2012, 08:46 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, it's years since I've written any XSLT 1.0 code, thank goodness. If you're really unable to move to 2.0, you'll have to look at what the EXSLT date-and-time library offers (assuming its available to you). If it's not available, you'll have to drop into some other language.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #5 (permalink)  
Old July 13th, 2012, 06:02 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Thanks for letting me know it is not possible to achieve this in version 1 for it is too hard.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
please help me how to count/convert date into days. juric.s SQL Server 2000 3 January 22nd, 2011 01:02 PM
Want jsp code to compare start date and end date rajeshree13 Java Basics 2 July 20th, 2009 03:10 AM
subtracting 1 day from the current date Jeff C# 2 March 12th, 2009 01:16 AM
Todays date and date of 3 days later Singh591 Visual Basic 2005 Basics 1 December 21st, 2006 06:06 PM
start date and an end date Corey Access 1 January 16th, 2006 12:37 AM



All times are GMT -4. The time now is 11:08 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.