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 AGEThis message has been edited. Last edited by: Kerry,
Mainly HTML..eventually XLS, PDF AHTML.
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.
I've been trying for most of the morning and am still no where close. Its all pretty new to me.
Mainly HTML..eventually XLS, PDF AHTML.
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 ENDHope this helps ...
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
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.
Win10 / IE11
AHTML EXL2K PDF
...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 B is correct, all you need is the DATEDIF function. Assume DOB is a Smart Date:
In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
I have tried this code,
DEFINE FILE xxxx
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;
TABLE FILE xxxx
PRINT BIRTHDATE AGE
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.
Windows, All Outputs
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.
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,
|Powered by Social Strata|