Title: calculation based on date
Last modified: January 28, 2025

---

# calculation based on date

 *  Resolved [kjou06](https://wordpress.org/support/users/kjou06/)
 * (@kjou06)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/calculation-based-on-date-2/)
 * Hello
   I need help to determine the price of a contribution based on the current
   date fieldname6for example:1) if the current date is between 2025/01/01 and 2025/
   04/30 the price is €2002) if the current date is between 2025/05/01 and 2025/
   06/30 the price is €1403) 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](https://wordpress.org/support/users/codepeople2/)
 * (@codepeople2)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/calculation-based-on-date-2/#post-18270425)
 * Hello [@kjou06](https://wordpress.org/support/users/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:
 *     ```wp-block-code
       (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](https://wordpress.org/support/users/kjou06/)
 * (@kjou06)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/calculation-based-on-date-2/#post-18270542)
 * 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](https://wordpress.org/support/users/codepeople2/)
 * (@codepeople2)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/calculation-based-on-date-2/#post-18270555)
 * Hello [@kjou06](https://wordpress.org/support/users/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
 *     ```wp-block-code
       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](https://wordpress.org/support/users/kjou06/)
 * (@kjou06)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/calculation-based-on-date-2/#post-18270588)
 * 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](https://wordpress.org/support/users/codepeople2/)
 * (@codepeople2)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/calculation-based-on-date-2/#post-18270605)
 * Hello [@kjou06](https://wordpress.org/support/users/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:
 *     ```wp-block-code
       (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](https://wordpress.org/support/users/kjou06/)
 * (@kjou06)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/calculation-based-on-date-2/#post-18270615)
 * Thank you very much. It’s perfect

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘calculation based on date’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

## Tags

 * [dates](https://wordpress.org/support/topic-tag/dates/)

 * 6 replies
 * 2 participants
 * Last reply from: [kjou06](https://wordpress.org/support/users/kjou06/)
 * Last activity: [1 year, 4 months ago](https://wordpress.org/support/topic/calculation-based-on-date-2/#post-18270615)
 * Status: resolved