calculating age of a person from DOB

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

calculating age of a person from DOB

ilango_g
Hi
I am trying to calculate the age of a person given his date of birth.
I tried the following code:

<xforms:instance id="taskinput">
                                        <fe:input>
                                                <fe:dob>1960-01-01</fe:arrestee_dob>
                                                <fe:age/>
                                        </fe:input>       
                                </xforms:instance>
       
                                <xforms:instance id="taskoutput">
                                        <fe:output>
                                                <fe:dob/>
                                                <fe:age/>
                                        </fe:output>       
                                </xforms:instance>

<xforms:output value="concat(substring(now(),1,4) - substring(instance('taskoutput')/fe:dob,1,4), ' years old')"/>

The General solution I have come up is as follows:
<xforms:output value="concat(substring(now(),1,4) - substring(instance('taskoutput')/fe:dob,1,4), ' years old') - number(if(substring(now(),6,2) >= 1 and substring(now(),9,2) >=1,'0','1' ))"/>


How can I properly make the casts and perform the arithmetic here?

thanks
ilango
Reply | Threaded
Open this post in threaded view
|

Re: calculating age of a person from DOB

Hank Ratzesberger
Ilango,

Between current-date() and the duration functions
that Orbeon supports, there is a way to do
this with xpath functions.

http://www.w3.org/TR/xpath-functions/

Cheers,
Hank


On Apr 30, 2008, at 8:23 AM, ilango_g wrote:

>
> Hi
> I am trying to calculate the age of a person given his date of birth.
> I tried the following code:
>
> <xforms:instance id="taskinput">
> <fe:input>
> <fe:dob>1960-01-01</fe:arrestee_dob>
> <fe:age/>
> </fe:input>
> </xforms:instance>
>
> <xforms:instance id="taskoutput">
> <fe:output>
> <fe:dob/>
> <fe:age/>
> </fe:output>
> </xforms:instance>
>
> <xforms:output value="concat(substring(now(),1,4) -
> substring(instance('taskoutput')/fe:dob,1,4), ' years old')"/>
>
> The General solution I have come up is as follows:
> <xforms:output value="concat(substring(now(),1,4) -
> substring(instance('taskoutput')/fe:dob,1,4), ' years old') -
> number(if(substring(now(),6,2) >= 1 and substring(now(),9,2)  
> >=1,'0','1'
> ))"/>
>
>
> How can I properly make the casts and perform the arithmetic here?
>
> thanks
> ilango
> --
> View this message in context: http://www.nabble.com/calculating-age- 
> of-a-person-from-DOB-tp16985305p16985305.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
Hank Ratzesberger
NEES@UCSB
Institute for Crustal Studies,
University of California, Santa Barbara
805-893-8042







--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: calculating age of a person from DOB

ilango_g
Thanks for pointing me out to this. I am still not able to figure out how to convert the results of my substring operations (a string) to a integer.
Should I apply a cast on each of the results of my substring functions?

Hank Ratzesberger wrote
Ilango,

Between current-date() and the duration functions
that Orbeon supports, there is a way to do
this with xpath functions.

http://www.w3.org/TR/xpath-functions/

Cheers,
Hank


On Apr 30, 2008, at 8:23 AM, ilango_g wrote:

>
> Hi
> I am trying to calculate the age of a person given his date of birth.
> I tried the following code:
>
> <xforms:instance id="taskinput">
> <fe:input>
> <fe:dob>1960-01-01</fe:arrestee_dob>
> <fe:age/>
> </fe:input>       
> </xforms:instance>
>
> <xforms:instance id="taskoutput">
> <fe:output>
> <fe:dob/>
> <fe:age/>
> </fe:output>       
> </xforms:instance>
>
> <xforms:output value="concat(substring(now(),1,4) -
> substring(instance('taskoutput')/fe:dob,1,4), ' years old')"/>
>
> The General solution I have come up is as follows:
> <xforms:output value="concat(substring(now(),1,4) -
> substring(instance('taskoutput')/fe:dob,1,4), ' years old') -
> number(if(substring(now(),6,2) >= 1 and substring(now(),9,2)  
> >=1,'0','1'
> ))"/>
>
>
> How can I properly make the casts and perform the arithmetic here?
>
> thanks
> ilango
> --
> View this message in context: http://www.nabble.com/calculating-age- 
> of-a-person-from-DOB-tp16985305p16985305.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the ops-users@ow2.org  
> mailing list.
> To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
> For general help: mailto:sympa@ow2.org?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws

Hank Ratzesberger
NEES@UCSB
Institute for Crustal Studies,
University of California, Santa Barbara
805-893-8042







--
You receive this message as a subscriber of the ops-users@ow2.org mailing list.
To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
For general help: mailto:sympa@ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: calculating age of a person from DOB

Hank Ratzesberger

Hi Ilango,

I found some strange things when I looked closer at this.  It
seems that subtracting two dates returns an xs:yearMonthDuration
in the format "PnnnnD' , i.e., always the number of days between dates,
but not the number of years.  Further, the following entered in the
xpath sandbox:

years-from-duration( xs:date('2008-02-29') - xs:date('2007-02-28') )

will return 0  (for some reason "P366D" is zero years?).

so, I recommend using regular arithmetic to calculate the years,
and hopefully this also will compensate for the
leap year when calculating age (in the event someone enters the leap
day for their birthday):

round( days-from-duration( current-date() - xs:date(/dob) )  div 365 )

replace '/dob' with the working xpath you your date of birth.

HTH,
Hank


On Apr 30, 2008, at 12:23 PM, ilango_g wrote:

>
> Thanks for pointing me out to this. I am still not able to figure  
> out how to
> convert the results of my substring operations (a string) to a  
> integer.
> Should I apply a cast on each of the results of my substring  
> functions?
>
>
> Hank Ratzesberger wrote:
>>
>> Ilango,
>>
>> Between current-date() and the duration functions
>> that Orbeon supports, there is a way to do
>> this with xpath functions.
>>
>> http://www.w3.org/TR/xpath-functions/
>>
>> Cheers,
>> Hank
>>
>>
>> On Apr 30, 2008, at 8:23 AM, ilango_g wrote:
>>
>>>
>>> Hi
>>> I am trying to calculate the age of a person given his date of  
>>> birth.
>>> I tried the following code:
>>>
>>> <xforms:instance id="taskinput">
>>> <fe:input>
>>> <fe:dob>1960-01-01</fe:arrestee_dob>
>>> <fe:age/>
>>> </fe:input>
>>> </xforms:instance>
>>>
>>> <xforms:instance id="taskoutput">
>>> <fe:output>
>>> <fe:dob/>
>>> <fe:age/>
>>> </fe:output>
>>> </xforms:instance>
>>>
>>> <xforms:output value="concat(substring(now(),1,4) -
>>> substring(instance('taskoutput')/fe:dob,1,4), ' years old')"/>
>>>
>>> The General solution I have come up is as follows:
>>> <xforms:output value="concat(substring(now(),1,4) -
>>> substring(instance('taskoutput')/fe:dob,1,4), ' years old') -
>>> number(if(substring(now(),6,2) >= 1 and substring(now(),9,2)
>>>> =1,'0','1'
>>> ))"/>
>>>
>>>
>>> How can I properly make the casts and perform the arithmetic here?
>>>
>>> thanks
>>> ilango
>>> --
>>> View this message in context: http://www.nabble.com/calculating-age-
>>> of-a-person-from-DOB-tp16985305p16985305.html
>>> Sent from the ObjectWeb OPS - Users mailing list archive at
>>> Nabble.com.
>>>
>>>
>>> --
>>> You receive this message as a subscriber of the [hidden email]
>>> mailing list.
>>> To unsubscribe: mailto:[hidden email]
>>> For general help: mailto:[hidden email]?subject=help
>>> OW2 mailing lists service home page: http://www.ow2.org/wws
>>
>> Hank Ratzesberger
>> NEES@UCSB
>> Institute for Crustal Studies,
>> University of California, Santa Barbara
>> 805-893-8042
>>
>>
>>
>>
>>
>>
>>
>> --
>> You receive this message as a subscriber of the [hidden email]  
>> mailing
>> list.
>> To unsubscribe: mailto:[hidden email]
>> For general help: mailto:[hidden email]?subject=help
>> OW2 mailing lists service home page: http://www.ow2.org/wws
>>
>>
>
> --
> View this message in context: http://www.nabble.com/calculating-age- 
> of-a-person-from-DOB-tp16985305p16989821.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
Hank Ratzesberger
NEES@UCSB
Institute for Crustal Studies,
University of California, Santa Barbara
805-893-8042







--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: calculating age of a person from DOB

ilango_g
Hi Hank
I got this to work yesterday with the below bind:

<xforms:bind nodeset="instance('taskoutput')/fe:arrestee_age" relevant="true()" type="xs:integer" calculate="if(substring(now(),1,4)
                                        castable as xs:integer and substring(instance('taskoutput')/fe:arrestee_dob,1,4) castable as xs:integer) then xs:integer(substring(now(),1,4)) - xs:integer( substring( instance('taskoutput')/fe:arrestee_dob,1,4) ) else '0'"/>

I will also prepare a separate sample according to your recommendations. Do let me know you opinion on my solution. Also my solution does not yet account for the leap year thing and the possibility of the user entering a date in the future (and getting some bizarre age as a result)

ilango

Hank Ratzesberger wrote
Hi Ilango,

I found some strange things when I looked closer at this.  It
seems that subtracting two dates returns an xs:yearMonthDuration
in the format "PnnnnD' , i.e., always the number of days between dates,
but not the number of years.  Further, the following entered in the
xpath sandbox:

years-from-duration( xs:date('2008-02-29') - xs:date('2007-02-28') )

will return 0  (for some reason "P366D" is zero years?).

so, I recommend using regular arithmetic to calculate the years,
and hopefully this also will compensate for the
leap year when calculating age (in the event someone enters the leap
day for their birthday):

round( days-from-duration( current-date() - xs:date(/dob) )  div 365 )

replace '/dob' with the working xpath you your date of birth.

HTH,
Hank


On Apr 30, 2008, at 12:23 PM, ilango_g wrote:

>
> Thanks for pointing me out to this. I am still not able to figure  
> out how to
> convert the results of my substring operations (a string) to a  
> integer.
> Should I apply a cast on each of the results of my substring  
> functions?
>
>
> Hank Ratzesberger wrote:
>>
>> Ilango,
>>
>> Between current-date() and the duration functions
>> that Orbeon supports, there is a way to do
>> this with xpath functions.
>>
>> http://www.w3.org/TR/xpath-functions/
>>
>> Cheers,
>> Hank
>>
>>
>> On Apr 30, 2008, at 8:23 AM, ilango_g wrote:
>>
>>>
>>> Hi
>>> I am trying to calculate the age of a person given his date of  
>>> birth.
>>> I tried the following code:
>>>
>>> <xforms:instance id="taskinput">
>>> <fe:input>
>>> <fe:dob>1960-01-01</fe:arrestee_dob>
>>> <fe:age/>
>>> </fe:input>       
>>> </xforms:instance>
>>>
>>> <xforms:instance id="taskoutput">
>>> <fe:output>
>>> <fe:dob/>
>>> <fe:age/>
>>> </fe:output>       
>>> </xforms:instance>
>>>
>>> <xforms:output value="concat(substring(now(),1,4) -
>>> substring(instance('taskoutput')/fe:dob,1,4), ' years old')"/>
>>>
>>> The General solution I have come up is as follows:
>>> <xforms:output value="concat(substring(now(),1,4) -
>>> substring(instance('taskoutput')/fe:dob,1,4), ' years old') -
>>> number(if(substring(now(),6,2) >= 1 and substring(now(),9,2)
>>>> =1,'0','1'
>>> ))"/>
>>>
>>>
>>> How can I properly make the casts and perform the arithmetic here?
>>>
>>> thanks
>>> ilango
>>> --
>>> View this message in context: http://www.nabble.com/calculating-age-
>>> of-a-person-from-DOB-tp16985305p16985305.html
>>> Sent from the ObjectWeb OPS - Users mailing list archive at
>>> Nabble.com.
>>>
>>>
>>> --
>>> You receive this message as a subscriber of the ops-users@ow2.org
>>> mailing list.
>>> To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
>>> For general help: mailto:sympa@ow2.org?subject=help
>>> OW2 mailing lists service home page: http://www.ow2.org/wws
>>
>> Hank Ratzesberger
>> NEES@UCSB
>> Institute for Crustal Studies,
>> University of California, Santa Barbara
>> 805-893-8042
>>
>>
>>
>>
>>
>>
>>
>> --
>> You receive this message as a subscriber of the ops-users@ow2.org  
>> mailing
>> list.
>> To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
>> For general help: mailto:sympa@ow2.org?subject=help
>> OW2 mailing lists service home page: http://www.ow2.org/wws
>>
>>
>
> --
> View this message in context: http://www.nabble.com/calculating-age- 
> of-a-person-from-DOB-tp16985305p16989821.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the ops-users@ow2.org  
> mailing list.
> To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
> For general help: mailto:sympa@ow2.org?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws

Hank Ratzesberger
NEES@UCSB
Institute for Crustal Studies,
University of California, Santa Barbara
805-893-8042







--
You receive this message as a subscriber of the ops-users@ow2.org mailing list.
To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
For general help: mailto:sympa@ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: calculating age of a person from DOB

Hank Ratzesberger

The available functions for dates and durations will
work as long as the date is in the correct format
(even that is locale dependent).  Even so, they
measure the duration in days, which can make leap
years problematic.

So, perhaps parsing the strings has its merits.

Cheers,
Hank

On May 1, 2008, at 7:44 AM, ilango_g wrote:

>
> Hi Hank
> I got this to work yesterday with the below bind:
>
> <xforms:bind nodeset="instance('taskoutput')/fe:arrestee_age"
> relevant="true()" type="xs:integer" calculate="if(substring(now(),1,4)
> castable as xs:integer and
> substring(instance('taskoutput')/fe:arrestee_dob,1,4) castable as
> xs:integer) then xs:integer(substring(now(),1,4)) - xs:integer
> ( substring(
> instance('taskoutput')/fe:arrestee_dob,1,4) ) else '0'"/>
>
> I will also prepare a separate sample according to your  
> recommendations. Do
> let me know you opinion on my solution. Also my solution does not yet
> account for the leap year thing and the possibility of the user  
> entering a
> date in the future (and getting some bizarre age as a result)
>
> ilango
>
>
> Hank Ratzesberger wrote:
>>
>>
>> Hi Ilango,
>>
>> I found some strange things when I looked closer at this.  It
>> seems that subtracting two dates returns an xs:yearMonthDuration
>> in the format "PnnnnD' , i.e., always the number of days between  
>> dates,
>> but not the number of years.  Further, the following entered in the
>> xpath sandbox:
>>
>> years-from-duration( xs:date('2008-02-29') - xs:date('2007-02-28') )
>>
>> will return 0  (for some reason "P366D" is zero years?).
>>
>> so, I recommend using regular arithmetic to calculate the years,
>> and hopefully this also will compensate for the
>> leap year when calculating age (in the event someone enters the leap
>> day for their birthday):
>>
>> round( days-from-duration( current-date() - xs:date(/dob) )  div  
>> 365 )
>>
>> replace '/dob' with the working xpath you your date of birth.
>>
>> HTH,
>> Hank
>>
>>
>> On Apr 30, 2008, at 12:23 PM, ilango_g wrote:
>>
>>>
>>> Thanks for pointing me out to this. I am still not able to figure
>>> out how to
>>> convert the results of my substring operations (a string) to a
>>> integer.
>>> Should I apply a cast on each of the results of my substring
>>> functions?
>>>
>>>
>>> Hank Ratzesberger wrote:
>>>>
>>>> Ilango,
>>>>
>>>> Between current-date() and the duration functions
>>>> that Orbeon supports, there is a way to do
>>>> this with xpath functions.
>>>>
>>>> http://www.w3.org/TR/xpath-functions/
>>>>
>>>> Cheers,
>>>> Hank
>>>>
>>>>
>>>> On Apr 30, 2008, at 8:23 AM, ilango_g wrote:
>>>>
>>>>>
>>>>> Hi
>>>>> I am trying to calculate the age of a person given his date of
>>>>> birth.
>>>>> I tried the following code:
>>>>>
>>>>> <xforms:instance id="taskinput">
>>>>> <fe:input>
>>>>> <fe:dob>1960-01-01</fe:arrestee_dob>
>>>>> <fe:age/>
>>>>> </fe:input>
>>>>> </xforms:instance>
>>>>>
>>>>> <xforms:instance id="taskoutput">
>>>>> <fe:output>
>>>>> <fe:dob/>
>>>>> <fe:age/>
>>>>> </fe:output>
>>>>> </xforms:instance>
>>>>>
>>>>> <xforms:output value="concat(substring(now(),1,4) -
>>>>> substring(instance('taskoutput')/fe:dob,1,4), ' years old')"/>
>>>>>
>>>>> The General solution I have come up is as follows:
>>>>> <xforms:output value="concat(substring(now(),1,4) -
>>>>> substring(instance('taskoutput')/fe:dob,1,4), ' years old') -
>>>>> number(if(substring(now(),6,2) >= 1 and substring(now(),9,2)
>>>>>> =1,'0','1'
>>>>> ))"/>
>>>>>
>>>>>
>>>>> How can I properly make the casts and perform the arithmetic here?
>>>>>
>>>>> thanks
>>>>> ilango
>>>>> --
>>>>> View this message in context: http://www.nabble.com/calculating- 
>>>>> age-
>>>>> of-a-person-from-DOB-tp16985305p16985305.html
>>>>> Sent from the ObjectWeb OPS - Users mailing list archive at
>>>>> Nabble.com.
>>>>>
>>>>>
>>>>> --
>>>>> You receive this message as a subscriber of the [hidden email]
>>>>> mailing list.
>>>>> To unsubscribe: mailto:[hidden email]
>>>>> For general help: mailto:[hidden email]?subject=help
>>>>> OW2 mailing lists service home page: http://www.ow2.org/wws
>>>>
>>>> Hank Ratzesberger
>>>> NEES@UCSB
>>>> Institute for Crustal Studies,
>>>> University of California, Santa Barbara
>>>> 805-893-8042
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> You receive this message as a subscriber of the [hidden email]
>>>> mailing
>>>> list.
>>>> To unsubscribe: mailto:[hidden email]
>>>> For general help: mailto:[hidden email]?subject=help
>>>> OW2 mailing lists service home page: http://www.ow2.org/wws
>>>>
>>>>
>>>
>>> --
>>> View this message in context: http://www.nabble.com/calculating-age-
>>> of-a-person-from-DOB-tp16985305p16989821.html
>>> Sent from the ObjectWeb OPS - Users mailing list archive at
>>> Nabble.com.
>>>
>>>
>>> --
>>> You receive this message as a subscriber of the [hidden email]
>>> mailing list.
>>> To unsubscribe: mailto:[hidden email]
>>> For general help: mailto:[hidden email]?subject=help
>>> OW2 mailing lists service home page: http://www.ow2.org/wws
>>
>> Hank Ratzesberger
>> NEES@UCSB
>> Institute for Crustal Studies,
>> University of California, Santa Barbara
>> 805-893-8042
>>
>>
>>
>>
>>
>>
>>
>> --
>> You receive this message as a subscriber of the [hidden email]  
>> mailing
>> list.
>> To unsubscribe: mailto:[hidden email]
>> For general help: mailto:[hidden email]?subject=help
>> OW2 mailing lists service home page: http://www.ow2.org/wws
>>
>>
>
> --
> View this message in context: http://www.nabble.com/calculating-age- 
> of-a-person-from-DOB-tp16985305p16993277.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
Hank Ratzesberger
NEES@UCSB
Institute for Crustal Studies,
University of California, Santa Barbara
805-893-8042







--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws