[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problem with Age Calculation

Subject: RE: Problem with Age Calculation
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 10 May 2008 22:48:47 +0100
RE:  Problem with Age Calculation
I think the problem is your use of "idiv" which does an integer division
(that is, the result is an integer number of years). Replace this by "div"
and your answer will then be to the nearest month.

Also note, you can now use the prefix xs where you use xdt - types like
dayTimeDuration and yearMonthDuration were moved into the XML Schema
namespace in the final draft of the spec.

Michael Kay
http://www.saxonica.com/  

> -----Original Message-----
> From: ilango [mailto:ilangocal@xxxxxxxxx] 
> Sent: 07 May 2008 03:26
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Problem with Age Calculation
> 
> Hi
> I am using Saxon 9.0.0.4 with XSLT 2.0 and XPATH 2.0. This is 
> my first post.
> I am using the following XPATH expression in an XForm. This 
> is not an XForm question.It is about the XPath in the XForm.
> 
> <xforms:bind nodeset="instance('taskoutput')/fe:age" 
> type="xs:integer" 
> calculate="if((instance('taskoutput')/fe:dob) castable as 
> xs:date) then (current-date() - 
> xs:date(instance('taskoutput')/fe:dob)) div xdt:dayTimeDuration('P1D')
> 								
> idiv 365.242199 
> 						* 
> xdt:yearMonthDuration('P1Y') else()"/>
> 
> I am not familiar with XPath date functions and I am finding 
> it hard to get the age from this expression.
> It returns me something P33Y or something for a certain input DOB.
> 
> What can I do to get the age of a person in years and months. 
> I am ok with  not having to account for leap years or small 
> problems at the boundaries.
> 
> All help is appreciated.
> 
> thanks
> ilango
> 
> 
> 
> 
>       
> ______________________________________________________________
> ______________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.  
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.