Support » Plugin: Calculated Fields Form » I cant put date function properly

  • Resolved munaka

    (@musaabbaskuru)


    I cant put date functions in calculated field hope u can help me with the simple format i should use. My calculation depends on the date span user chooses. I checked online how to pu date in java but i dont know how to apply it to your calculated field area.

    Fieldname1 is date field
    Fieldname2 is number

    If fieldname1 is between 01/01/2019-31/12/2019 return fieldname2*5;

    If fieldname1 is between 01/06/2018-31/12/2018 return fieldname2*8;

    If fieldname1 is between 01/01/2018-31/05/2018 return fieldname2*13;

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

    (@codepeople)

    Hello,

    The process is really simple, as the comparison in this case is between texts, I recommend you the following code (as you can see I’m formatting the date as yyyy-mm-dd to make the comparison unequivocal):

    
    (function(){
       var d = CDATE('yyyy-mm-dd');
       if(d<='2018-05-31') return fieldname2*13;
       if(d<='2018-12-31') return fieldname2*8;
       return fieldname2*5;
    })()
    

    and that’s all.
    Best regards.

    munaka

    (@musaabbaskuru)

    Hi thank you for your answer.
    However you didnt put any data about fieldname1 and it only multiples by 5 because of the last return and other functions dont apply. Only *5 aplies. I copy pasted your function to calculated area.

    Plugin Author codepeople

    (@codepeople)

    Hello @musaabbaskuru

    I’m sorry, my fault:

    
    (function(){
       var d = CDATE(fieldname1, 'yyyy-mm-dd');
       if(d<='2018-05-31') return fieldname2*13;
       if(d<='2018-12-31') return fieldname2*8;
       return fieldname2*5;
    })()
    

    Best regards

    munaka

    (@musaabbaskuru)

    It works! Thanks a lot.

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