Skip to main content
July 11, 2023
Question

Query to add an integer (day) to a date

  • July 11, 2023
  • 4 replies
  • 0 views

Hi! I´m trying to query a database which has:

- A date field (month-day-year)

- A number of days to add (integer)

I want to use a query in order to add the number of days (integer, I want it to be days) to the date field, and return a date field. 

I tried the following query but it doesnt work (returns null). And the function ADD_DATE is not able in appian. What can i do?

    4 replies

    mikes0011
    Brainy
    July 11, 2023

    This would be far easier to do just by writing an expression using Query Entity to fetch the date from the row in question and then add the number of days to it.  In general I strongly recommend against using the Query DB nodes like this unless there's absolutely no other option.

    The Expression Guru
    mathieud0001
    Brainy
    July 12, 2023

    Agree with Mike - get the data but do the add operation within Appian.

    July 12, 2023

    You can fetch the date and the no of days to be  added from the database to expression rule using the query entity and follow the below code for the desired Output. If you want to add multiple data you can use forEach().

    a!localVariables(
    /* Fetch the date and no of days to be added using query entity*/
      local!date:today(),
      local!noOfDays:2,
      local!result:local!date+local!noOfDays,
      local!result
    )

    July 12, 2023

    In the end I just made a sum of the process variables in the e-mail form, that was enough for me. Also, in the database I could do the same with a new custom record. Thanks!