Compare field in display with actual date

Tags:
AS/400
I have a field in my display ( @invdate 8y 0 edtcde(y). I want to compare this field with actual date, my field is dd/mm/yyyy. How can I make the comparison?
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • philpl1jb

    Today in numeric 8 ddmmyyyy is:

    %dec(%date() : *EUR)

    So I would think it would be something like this.

    if @invdate = %dec(%date() : *EUR)

    54,090 pointsBadges:
    report
  • NeilD

    There are many ways to go about this. Here's one way... 

    First, obtain todays date in ccyymmdd:

    Todaysdate = %dec(%char(%date():*iso0): 8:0); // TodaysDate is 8,0

    Then convert your @INVDATE from DDMMCCYY to CCYYMMDD format: 

    #INVDATE = %char(%date(@INVDATE:*eur0):*iso0); // #INVDATE is 8,0

    Now compare the two.

    if #invdate = TodaysDate;

    (do something)

    endif;

    570 pointsBadges:
    report
  • philpl1jb
    Neil's is better .. since your field @invdate is char mine won't work
    54,090 pointsBadges:
    report
  • TheRealRaven
    How can I make the comparison?

    What "comparison" is needed? You might choose different methods depending on whether you only need to know equal/not equal or you need to know greater/less than.

    It's most often best to get both terms into a matching appropriate format such as YYYYMMDD, but there can be cases when DDMMYYYY works for both terms.
    36,115 pointsBadges:
    report
  • philpl1jb

    Wondering in the desert .. my original proposal would work find @invdate is indeed a numeric field.

    Converting today %date() cannot fail

    Converting @invdate to a date can fail

    If you feel that you must convert @invdate to a date include the code in a monitor block.

    54,090 pointsBadges:
    report
  • ToddN2000
    Neil's method is probably your best bet. The only thing that would cause an issue is if there is invalid data in the date field. I have seen system where people in IT have had to "fix" some bad data either using a DFU or SQL and updated a record with a bad date. Like 31/05/2015.
    134,930 pointsBadges:
    report
  • TheRealRaven
    But if it's not compared as an actual DATE data type, an 'invalid' date won't cause an error. And if it's intended to be an "equal" comparison, it might not even be an issue.

    Without knowing the business problem, it's hard to know what's appropriate.
    36,115 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: