p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Subtracting end date - inital date but count only week days not Saturdays and Sundays (http://p2p.wrox.com/showthread.php?t=87981)

pallone July 12th, 2012 04:54 PM

Subtracting end date - inital date but count only week days not Saturdays and Sundays

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.

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




mhkay July 12th, 2012 05:24 PM

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)).

pallone July 13th, 2012 07:56 AM

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).



mhkay July 13th, 2012 08:46 AM

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.

pallone July 13th, 2012 06:02 PM

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

All times are GMT -4. The time now is 12:03 PM.

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