Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Calculate Age while taking into account leap years

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED] Calculate Age while taking into account leap years
 Login/Join
 
Member
posted
Hello

Am new to the forum and Web focus.

I would like to be able to work out a person's name while taking into account the leap years.

Dividing by 365.25 is not accurate enough for what I want to do as its quite sensitive. I've also tried to do a datediff but thats not accurate enough.

I have searched for previous posts but non of them have what I need.

PS: I can do this quite easily in MS SQL. See code below :

SELECT DATEDIFF(YY, @BirthDate, @CurrentDate) - CASE WHEN( (MONTH(@BirthDate)*100 + DAY(@BirthDate)) > (MONTH(@CurrentDate)*100 + DAY(@CurrentDate)) ) THEN 1 ELSE 0 END AS AGE

This message has been edited. Last edited by: Kerry,


WebFOCUS 7.7.3
PMF 5.3.1,
Windows,
Mainly HTML..eventually XLS, PDF AHTML.
 
Posts: 3 | Registered: October 18, 2010Report This Post
Virtuoso
posted Hide Post
You can do the same of course in webfocus. Extract all the same portions from the dates involved and do the same logic. It will look a little bit different from how it looks in MS SQL, but the logic is the same and it will give you the same result.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
 
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007Report This Post
Member
posted Hide Post
Thanks.

I've been trying for most of the morning and am still no where close. Its all pretty new to me.


WebFOCUS 7.7.3
PMF 5.3.1,
Windows,
Mainly HTML..eventually XLS, PDF AHTML.
 
Posts: 3 | Registered: October 18, 2010Report This Post
Virtuoso
posted Hide Post
Ok, here goes. This is assuming you have the birthdate as a YYMD field. If not, you'll have to do some conversion.
DEFINE FILE xxxx
-*Extract years
CDYY/YY = &DATEYY;
BDYY/YY = BIRTHDATE;
-* Compute difference
YEARS/I4 = CDYY - BDYY;
-* Extract month/day
CDMD/I8 = &MDYY / 10000;
HELP/A8YYMD = BIRTHDATE;
BDMD/I8 = EDIT(EDIT(HELP,'$$$$9999'));
-* See if a year must be subtracted
SUBYEAR/I4 = IF BDMD GT CDMD THEN 1 ELSE 0;
-* Compute age
AGE/I4 = YEARS - SUBYEAR;
END
TABLE FILE xxxx
PRINT BIRTHDATE AGE
END
Hope this helps ...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
 
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007Report This Post
Virtuoso
posted Hide Post
I must be missing something here. DATEDIF works quite well I find, leap years included.

DEFINE FILE CAR
-*TODAY/DMYY = '&DATEDMYY';	
TODAY/DMYY = '28/02/1997';	
PAST/YYMD = '1996/02/29';
YRS/I2 = DATEDIF(PAST,TODAY,'Y');
MTH/I2 = DATEDIF(DATEADD(PAST,'Y',YRS),TODAY,'M');
DAY/I2 = DATEDIF(DATEADD(PAST,'M',(YRS*12)+MTH),TODAY,'D');
END
TABLE FILE CAR
PRINT YRS AS 'Year(s)'
      MTH AS 'Month(s)'
      DAY AS 'Day(s)'  
BY HIGHEST 1 COUNTRY NOPRINT
END


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Platinum Member
posted Hide Post
Yea, not really a leap year issue. Looks like it was more about not counting the current year in the age until you have your birthday in the current year. Looks like GamP nailed it.


WebFOCUS 8.2.06
 
Posts: 210 | Location: Sterling Heights, Michigan | Registered: October 19, 2010Report This Post
Virtuoso
posted Hide Post
...and that is what DATEDIF does. It looks at the complete dates, not just the yeaar portion, and provides the correct number of years, as in the correct age of a person.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Master
posted Hide Post
Alan B is correct, all you need is the DATEDIF function. Assume DOB is a Smart Date:
CURRDT/YYMD=&YYMD;
AGE/I4=DATEDIF(DOB,CURRDT,'Y');


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
 
Posts: 975 | Location: Oklahoma City | Registered: October 27, 2006Report This Post
Member
posted Hide Post
Hi,

I have tried this code,

DEFINE FILE xxxx
-*Extract years
CDYY/YY = &DATEYY;
BDYY/YY = BIRTHDATE;
-* Compute difference
YEARS/I4 = CDYY - BDYY;
-* Extract month/day
CDMD/I8 = &MDYY / 10000;
HELP/A8YYMD = BIRTHDATE;
BDMD/I8 = EDIT(EDIT(HELP,'$$$$9999'));
-* See if a year must be subtracted
SUBYEAR/I4 = IF BDMD GT CDMD THEN 1 ELSE 0;
-* Compute age
AGE/I4 = YEARS - SUBYEAR;
END
TABLE FILE xxxx
PRINT BIRTHDATE AGE
END

it does work in a procedure but when i call the procedure in HTML it gives me the following error

FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: CDYY

FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: CDMD

FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: YEARS

Do we need to declare variables? or what is missing. because it does work if i run the procedure indiviually.


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 11 | Registered: October 13, 2010Report This Post
Virtuoso
posted Hide Post
Those &variables you're using are assumed to always be there so you shouldn't need to declare/default them.

Can you add:
-SET &ECHO=ON;
at the beginning of your procedure to see what code is WebFOCUS actually running.

In addition to that, could you please post the HTML piece where your procedure is being invoked?

When posting, please make sure to enclose your code using the </> button in the message toolbar.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
 
Posts: 1533 | Registered: August 12, 2005Report This Post
Virtuoso
posted Hide Post
So, let me get this straight -- at no point did anyone in IB-land consider returning the result as a real number so you could just truncate the pig? This is a crazy level of effort to figure out how old somebody is.

This message has been edited. Last edited by: John_Edwards,



 
Posts: 1012 | Location: At the Mast | Registered: May 17, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Calculate Age while taking into account leap years

Copyright © 1996-2020 Information Builders