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 29th, 2013, 11:10 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default Get Years Between Two Dates

Hi,
I need to get the number of years between two dates, which I have managed in a roundabout way, but surely there is a more streamlined solution?

My code is:
Code:
 years-from-duration(((current-date() - xsd:date(otherDate)) div xsd:dayTimeDuration('P1D')) div 365.242199 * xsd:yearMonthDuration('P1Y'))"
This works but relies on a division of 365.242199 days.

I appreciate XPath is not a programming language, so maybe this is the only way, but is there anything in place that would return the number of years more accurately?

Thanks in advance.
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.
 
Old July 29th, 2013, 11:26 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It would be interesting to know what you think the rules should be. For example how many years are there between 28 Feb 2013 and 29 Feb 2012? The reason there's no function/operator for this in XPath 2.0 is because the WG couldn't agree on detailed semantics.
__________________
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:
Belch (July 30th, 2013)
 
Old July 30th, 2013, 04:40 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Yes I thought that might be the case, I just wanted to check there wasn't a date function I hadn't spotted.

The sooner we can start using Star Trek "stardates", the better!

Thanks for your help.
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Two years old - still a worthy buy? hypomnesis BOOK: Professional WordPress 4 January 7th, 2016 08:36 AM
adding years to date Israr JSP Basics 1 March 23rd, 2007 07:56 AM
Years to Months Conversion mahajanvit ASP.NET 2.0 Basics 2 September 25th, 2006 11:43 PM
Query by years anukagni Access 3 September 6th, 2006 06:11 AM
leap years & cal_days_in_month richard.york Pro PHP 4 December 27th, 2003 02:15 AM





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