Page 1 of 1

Age from date

PostPosted: Wed Aug 19, 2015 4:25 pm
by stu
Hi, I'm trying to come up with a formula to calculate the age of a person according to the date of birth, to be honest I think I can live without this but I dunno, using TSQL in the past I have used SELECT DATEDIFF(hour,@Param1,GETDATE())/8766 AS AgeTrunc and I was also taking a closer look at something like this: http://mathforum.org/library/drmath/view/59234.html

Is there a easier or better way of doing the same in Neobook?

Regards.

Re: Age from date

PostPosted: Wed Aug 19, 2015 5:17 pm
by AsleyCruz
Hi stu_
I used a VBScript to get the age from age.
Hope this code helps:

No plugins needed!

Code: Select all
Birthday = "[%1]"
Result = DateDiff("D",Birthday,Date)
TrueAge = Result / 365
TrueAge = Left(TrueAge,2)
publication.nbSetVar "[%2]", TrueAge


[%1] enter the birthday
[%2] variable to store the age

Regards_

Re: Age from date

PostPosted: Wed Aug 19, 2015 5:30 pm
by Ghatoo
Hola stu

Claro que hay una forma muy fácil, utiliza la función npYearsBetween del plugin nputil
Of course there is a very easy way, use the function npYearsBetween of the nputil plugin

Saludos
Jairo Moreno

Re: Age from date

PostPosted: Thu Aug 20, 2015 3:43 am
by stu
Ghatoo wrote:Hola stu

Claro que hay una forma muy fácil, utiliza la función npYearsBetween del plugin nputil
Of course there is a very easy way, use the function npYearsBetween of the nputil plugin

Saludos
Jairo Moreno


AsleyCruz wrote:Hi stu_
I used a VBScript to get the age from age.
Hope this code helps:

No plugins needed!

Code: Select all
Birthday = "[%1]"
Result = DateDiff("D",Birthday,Date)
TrueAge = Result / 365
TrueAge = Left(TrueAge,2)
publication.nbSetVar "[%2]", TrueAge


[%1] enter the birthday
[%2] variable to store the age

Regards_


Only thing I'm thinking is, does these methods take leap years in account? Thanks for the replies! =)

Re: Age from date

PostPosted: Thu Aug 20, 2015 5:49 am
by Gaev
Stu:

NeoBook has built-in facilities for this ... from the Help file ...
Code: Select all
DateToNum "12/15/2004" "m/d/y" "[StartDate]"
DateToNum "[DateShort]" "Default" "[Today]"
Math "[Today]-[StartDate]" "0" "[Result]"
AlertBox "Answer" "It has been [Result] days since 12/15/2004"

Re: Age from date

PostPosted: Fri Aug 21, 2015 7:38 am
by stu
Gaev wrote:Stu:

NeoBook has built-in facilities for this ... from the Help file ...
Code: Select all
DateToNum "12/15/2004" "m/d/y" "[StartDate]"
DateToNum "[DateShort]" "Default" "[Today]"
Math "[Today]-[StartDate]" "0" "[Result]"
AlertBox "Answer" "It has been [Result] days since 12/15/2004"


Yeah, I wasnt sure about this method because of the Leap years but you know what, I'm just gonna drop that... Maybe its not even needed for the end product...

Thanks! :mrgreen:

Re: Age from date

PostPosted: Sat Aug 22, 2015 10:48 am
by virger
I use yhis way, i dont' have any problem. Maybe can help you.

Code: Select all
...BirthDay fmt 'day/month/year'
setvar "[FecNac]" "![d]/[m]/19[y]"
strparse "[FecNac]" "/" "[dmy]" "[x]"
math "[Year]-[dmy3]" "" "[Age]"
math "[MonthNum]-[dmy2]" "" "[Mes]"
if "[Mes]" "<" "0"
    math "[Age]-1" "" "[Age]"
endif

GdoSan/Dr.Sanchez--El Jubilado..Abril 2015
GdoSan/Dr.Sanchez--The Retired..April 2015