# WordPress.org

## Calculated Fields Form[resolved] Fixed value between two dates (5 posts)

1. damiend1
Member
Posted 2 years ago #

Hello,

I have a table with fixed values​​:

1 day = 15 €
2 days = 27 €
more than 2 days = € 5 per additional day

Is it possible to calculate this with the module date?

Damien

2. codepeople
Member
Plugin Author

Posted 2 years ago #

Hi,

Suppose your form includes two date fields, start date (called fieldname1) and end date (called fieldname2), the corresponding equation in this case would be:

(function(){
var r = abs(fieldname2-fieldname1);
if( r == 1) return 15;
if( r == 2) return 27;
if( r > 2 ) return 5*r;
})();

Note: Transform the previous equation with the fields names used in your form.

3. damiend1
Member
Posted 2 years ago #

Hi,

Tanks it works !

After this i just need to add a somme for an option, How its possible to calculate, the result of the function above and other variable.

Tanks

4. codepeople
Member
Plugin Author

Posted 2 years ago #

Hi,

Suppose that your equation includes another field (called fieldname3) that should be added to the value related with the date fields, in this case the equation should be modified like follow:

(function(){
var r = abs(fieldname2-fieldname1);
var n;
if( r == 1) n = 15;
if( r == 2) n = 27;
if( r > 2 ) n = 5*r;

return n+fieldname3;
})();

Note: the previous equation is only a demo, but contains the pattern to create your own equation.

5. damiend1
Member
Posted 2 years ago #

Wouaw tanks ! amazing plugin, just need to go to pro version !

This topic has been closed to new replies.