• Resolved kjou06

    (@kjou06)


    Hello
    I need help to determine the price of a contribution based on the current date fieldname6
    for example:
    1) if the current date is between 2025/01/01 and 2025/04/30 the price is €200
    2) if the current date is between 2025/05/01 and 2025/06/30 the price is €140
    3) if the current date is between 2025/09/01 and 2025/12/31 the price is €110

    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author CodePeople2

    (@codepeople2)

    Hello @kjou06

    Thank you very much for using our plugin. Assuming the date field is the fieldname123, you can insert a calculated field in the form and enter the equation:

    (function(){
    let d = CDATE(fieldname123, 'yyyy/mm/dd');
    if (d<='2025/04/30') return 200;
    if (d<='2025/06/30') return 140;
    return 110;
    })()

    You need only to replace fieldname123 in the previous equation with the name of the date field in your form.

    Best regards.

    Thread Starter kjou06

    (@kjou06)

    Thanks for the super fast reply but it doesn’t work because the calculation field would have to detect if the current date is between two dates.
    In your equation,
    (function(){
    let d = CDATE(fieldname123, ‘yyyy/mm/dd’);
    if (d<=’2025/04/30′) return 200; if (d<=’2025/06/30′) return 140; return 110; })() the rate remains the same if the date <= 2025/04/30 or <= 2025/06/30 since the equation does not calculate if the date is >= 2025/30/04 AND <= 2025/30/06

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @kjou06

    I’m sorry, but what you say is incorrect. The use of return instruction stops the evaluation of the equation returning a result, the other lines in the equation are not evaluated.

    If the following condition is satisfied

    if (d<='2025/04/30') return 200; 

    The equation returns 200 and the second condition is never reached.

    Have you tested the equation?

    Best regards.

    Thread Starter kjou06

    (@kjou06)

    Sorry. It actually works fine with the yyyy/mm/dd date format but if my date field is formatted in dd/mm/yyyy, it doesn’t work anymore

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @kjou06

    You are describing a different situation. The code I recommended previously is based on your initial question, where is feasible to compare them alphabetically. But if you change the date format, you cannot compare them as texts and must convert them into date objects. In this case, the equation would be:

    (function(){
    let d = DATEOBJ(fieldname123, 'dd/mm/yyyy');
    if (d<=DATEOBJ('30/04/2025', 'dd/mm/yyyy')) return 200;
    if (d<=DATEOBJ('30/06/2025', 'dd/mm/yyyy')) return 140;
    return 110;
    })()

    Best regards.

    Thread Starter kjou06

    (@kjou06)

    Thank you very much. It’s perfect

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.