Support » Plugin: Calculated Fields Form » How to add to calculated value if a specific date is within a date range?

  • Resolved bnparks

    (@bnparks)


    I am creating a quote/estimate form for services that are scheduled and span over several days, and I want to include holiday surcharges that apply only to specific days. Is there a way to calculate additional values if a specific date falls within a date range?

    I have two date/time field already and calculate how many days it spans to calculate a daily rate, but can’t figure out how to include surcharges if one of those dates includes a holiday.

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @bnparks

    First, I recommend you to have the holiday dates in the format: yyyy-mm-dd because would be simpler compare them alphabetically, the date fields can be in a different format if you want.

    So, assuming the date fields are: fieldname1 and fieldname2 respectively, and you want to know if your holiday date: 2019-12-25 is between them, a possibility would be implement the equation as follows (the values are hypothetical only to describe the process):

    
    (function(){
    var _holiday = '2019-12-25',
        _days = ABS(fieldname2-fieldname1),
        _from = CDATE(MIN(fieldname2,fieldname1),'yyyy-mm-dd'),
        _to = CDATE(MAX(fieldname2,fieldname1),'yyyy-mm-dd'), 
        result  = days*20;
    if(_from<=_holiday && _holiday<=_to) result += 20;
    return result;
    })()
    

    The previous code multiply the number of days by 20, and increase the result in other 20 if the date range includes the holiday date.

    If you need additional help implementing your project, you should contact us through our private website: Customization

    Best regards.

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