• Resolved mpbaweb

    (@mpbaweb)


    Hi I am trying to return a value when a date falls between 2 other dates. The purpose of this is so I can assign a discount by multiplying another number by the result. I have tried this so far, but I am not getting any values returned. Can you tell me what I am doing wrong please?

    (function(){

    if(fieldname3 < ‘2022-08-01’ ) return 1;
    if(fieldname3 > ‘2022-08-30’ ) return 1;
    if(fieldname3 >= ‘2022-08-01’ and fieldname3 <= ‘2022-08-30’) return 0.5;

    })()

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @mpbaweb

    If the fieldname3 field is date/time field, you must transform its value to the same format of the date to compare.

    The and operator is represented by the double symbol &&.

    In your case, the last conditional statement is unnecessary, and you can group the two first in only one conditional statement with OR operator (||).

    So, the equation would be similar to:

    (function(){
    var d = CDATE(fieldname3, 'yyyy-mm-dd'); 
    if(d < '2022-08-01' ||  d > '2022-08-30') return 1;
    return 0.5;
    })()

    Best regards.

    Thread Starter mpbaweb

    (@mpbaweb)

    Thank you so much that works perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Date Calculation’ is closed to new replies.