Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2012, 04:54 PM
Friend of Wrox
 
Join Date: Oct 2003
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
 
Old July 12th, 2012, 05:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
The Following User Says Thank You to mhkay For This Useful Post:
pallone (July 13th, 2012)
 
Old July 13th, 2012, 07:56 AM
Friend of Wrox
 
Join Date: Oct 2003
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
 
Old July 13th, 2012, 08:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old July 13th, 2012, 06:02 PM
Friend of Wrox
 
Join Date: Oct 2003
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.





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.