doubt about how to validate two dates.

Hi, I have a question, I need to evaluate two dates, one I have already solved, the one I have solved is like this:

I have a date, and I have to validate with a boolean that must receive a data from 3 months to here, if it is more than 3 months, it is already an invalid date, but the part that I have not solved is, that I mark an invalid date from tomorrow.

I have compared it with an or, but it gives me true, I have this code, and it returns a true

if(
local!tipoComprobante = "INVOICE",
a!localVariables(
local!extraeFecha: substitute(right(local!fechaRecibida, 9), " ", "-"),
local!mes: rule!months(month:extract(local!extraeFecha, "-")),
local!fechaValida: concat(local!mes, "/", left(local!extraeFecha, 2), "/", "20", right(local!extraeFecha, 2)),

or(
today() <= edate(local!fechaValida,3),
today()+1>local!fechaValida)
),
false
)

this code block is inside an if, could I get some suggestions?

my local variable receives a date with this DD/MM/YYYY format.

Thanks!

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    Hi Gustavo, 

    I think you are doing a workaround to format the received date (text) to date type in the current standard of your Appian environment. 

    I see in the first local variable, you should put 10 as the parameter for the right() function, as a date has 10 characters: example: 11/11/2023 -> 10 characters.

    But I think this logic would be easier: 

    a!localVariables(
      local!tipoComprobante,
      /*I format the date I received to the standard*/
      local!formatDateText: datetext(userdatevalue(ri!date), "dd/MM/yyyy"),
      /* I transform it to date type*/
      local!finalDate: todate(local!formatDateText),
      /*Apply the logic needed*/
      {
        if(
          local!tipoComprobante = "INVOICE",
          or(
            today() <= edate(local!finalDate, 3),
            today() + 1 > local!finalDate
          )
        ),
        false
      }
    )

    Let me know if it works!