Page 1 of 1

Days Elapsed since Date

Posted: Fri Sep 01, 2017 4:05 pm
by John
I need to calculate the days elapsed since the Invoice date.

I've searched through the Technical Reference Guide online and found the DATEDIFFERENCE bif. I tried this BIF in my web page but got the error that 'Use is not supported on the web'. Is there a way to use it in my web page? So I used it in my server module.

Use Builtin(DATEDIFFERENCE) With_Args(*date8 A #WIDT20 1)
TO_GET(#StkAgeDays)

But I get these errors:
Value 1 is not valid for parameter DATEDIFFERENCE.
Missing output arguments for built-in function DATEDIFFERENCE (Required 1; Supplied 0).
Invalid or unexpected character at column 1.
TO_GET( #StkAgeDays ) is not a valid name.

The Technical Reference says:
•Valid formats for first and second dates: A, B, D, F, H, J, L, V and 1.

So 1 has a date format = CYYMMDD and WIDT20 comes from the Iseries as 7,0P in said format.
And A is in system date format.

StkAgeDays is a field I created in the repository and checked-in as Type = Signed and Length = 4.

What do I need to do to get this to work please?

Re: Days Elapsed since Date

Posted: Fri Sep 01, 2017 6:05 pm
by dannyoorburg
Hi John,

Have you tried the Date.Difference intrinsic?

http://docs.lansa.com/14/EN/LANSA016/PR ... erence.htm

You should be able to compare a date with Date.Now.

Goodluck,
Danny

Re: Days Elapsed since Date

Posted: Fri Sep 01, 2017 7:07 pm
by MarkDale
This way would work

Define Field(#D8) Type(*dec) Length(8) Decimals(0)
Use Builtin(CONVERTDATE_NUMERIC) With_Args(#WIDT20 '1' J) To_Get(#D8 #STD_CODES)
Use Builtin(DATEDIFFERENCE) With_Args(#YYYYMMDD J #D8 J) To_Get(#StkAgeDays #STD_CODES #STD_ALPHA)

or

Define Field(#D8) Type(*dec) Length(8) Decimals(0)
Use Builtin(CONVERTDATE_NUMERIC) With_Args(#WIDT20 '1' J) To_Get(#D8 #STD_CODES)
#StkAgeDays := #DATEX.Now.Difference( #D8.AsDate( CCYYMMDD ) )

Re: Days Elapsed since Date

Posted: Wed Sep 20, 2017 2:32 pm
by John
Thanks for both your input.

I experimented and found this works:
#StkAgeDays := #DATEX.Now.Difference( #WIDT20.asdate( xYYMMDD ) )