Days Elapsed since Date

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
John
Posts: 24
Joined: Thu Aug 10, 2017 3:21 pm

Days Elapsed since Date

Post 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?
dannyoorburg
Posts: 177
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Re: Days Elapsed since Date

Post 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
MarkDale
Posts: 116
Joined: Wed Dec 02, 2015 10:06 am

Re: Days Elapsed since Date

Post 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 ) )
John
Posts: 24
Joined: Thu Aug 10, 2017 3:21 pm

Re: Days Elapsed since Date

Post by John »

Thanks for both your input.

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