Title: Math with dates?
Last modified: August 30, 2016

---

# Math with dates?

 *  [mziebinski](https://wordpress.org/support/users/mziebinski/)
 * (@mziebinski)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/math-with-dates/)
 * I need to subtract a start date from an end date to get the total number of days
   in between. Can this be done?
 * [https://wordpress.org/plugins/caldera-forms/](https://wordpress.org/plugins/caldera-forms/)

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

 *  [mkocher](https://wordpress.org/support/users/mkocher/)
 * (@mkocher)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/math-with-dates/#post-6825817)
 * I also have this question. 🙂
 *  [howardjennings](https://wordpress.org/support/users/howardjennings/)
 * (@howardjennings)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/math-with-dates/#post-6825829)
 * I need to subtract 2 dates to find the number of months. how do I do that?
 *  [fudgite](https://wordpress.org/support/users/fudgite/)
 * (@fudgite)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/math-with-dates/#post-6825853)
 * You’ll need to update the `caldera-forms/fields/calculation/field.php` file.
 * Change this line (~62)
 *     ```
       $binds_vars[] = $fid . " = parseFloat( $('[data-field=\"" . $fid . "\"]').is(':checkbox') ? checked_total_" . $field_base_id . "($('[data-field=\"" . $fid . "\"]:checked')) : $('[data-field=\"" . $fid . "\"]').is(':radio') ? $('[data-field=\"" . $fid . "\"]:checked').val() : $('[data-field=\"" . $fid . "\"]').val() ) || 0 ";
       ```
   
 * With this :
 *     ```
       if($cfg['type'] == 'date_picker') {
       	$binds_vars[] = $fid." = ((new Date( $('[data-field=\"".$fid."\"]').val() )) / (1000 * 3600 * 24))";
       } else {
       	$binds_vars[] = $fid . " = parseFloat( $('[data-field=\"" . $fid . "\"]').is(':checkbox') ? checked_total_" . $field_base_id . "($('[data-field=\"" . $fid . "\"]:checked')) : $('[data-field=\"" . $fid . "\"]').is(':radio') ? $('[data-field=\"" . $fid . "\"]:checked').val() : $('[data-field=\"" . $fid . "\"]').val() ) || 0 ";
       }
       ```
   
 * This will convert your date to a number of days. So when you substract dates,
   you’ll get number of days between them.
 *  [fudgite](https://wordpress.org/support/users/fudgite/)
 * (@fudgite)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/math-with-dates/#post-6825854)
 * You also have to change the `Caldera_Forms::run_calculation()` function in `caldera-
   forms/classes/core.php` (~1017)
 * Search for this : (~1049)
 *     ```
       if (is_array($entry_value)) {
       	$number = floatval(array_sum($entry_value));
       } else {
       	$number = floatval($entry_value);
       }
       ```
   
 * To change it for :
 *     ```
       if($cfg['type'] == 'date_picker') {
       	$number = empty($entry_value) ? 0 : (strtotime($entry_value) / (3600 * 24));
       } else {
       	if (is_array($entry_value)) {
       		$number = floatval(array_sum($entry_value));
       	} else {
       		$number = floatval($entry_value);
       	}
       }
       ```
   
 * Forked it in with the fix my Github :
    [https://github.com/pboissonneault/Caldera-Forms](https://github.com/pboissonneault/Caldera-Forms)
 *  [venom791](https://wordpress.org/support/users/venom791/)
 * (@venom791)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/math-with-dates/#post-8360433)
 * I tried the above changes, however it did not work and it broke all calculation.
   Do you perhaps have a solution for the latest version of the plugin (Version 
   1.4.3.1)

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

The topic ‘Math with dates?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/caldera-forms_475846.svg)
 * [Caldera Forms - More Than Contact Forms](https://wordpress.org/plugins/caldera-forms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/caldera-forms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/caldera-forms/)
 * [Active Topics](https://wordpress.org/support/plugin/caldera-forms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/caldera-forms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/caldera-forms/reviews/)

 * 5 replies
 * 5 participants
 * Last reply from: [venom791](https://wordpress.org/support/users/venom791/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/math-with-dates/#post-8360433)
 * Status: not resolved