Block Date Ranges via Exceptions

Instructions

See “Where do I put snippets?” in our documentation for installation instructions.

Code

Filename: gpld-block-date-ranges.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
 * Gravity Perks // GP Limit Dates // Block Date Ranges via Exceptions
 */
add_filter( 'gpld_limit_dates_options_FORMID_FIELDID', 'gpld_except_date_ranges', 10, 3 );
function gpld_except_date_ranges( $options, $form, $field ) {
	/**
	 * Format: Start Date, End Date
	 */
	$ranges = array(
		array( '2016-07-15', '2017-01-01' ),
		array( '2020-12-10', '2020-12-20' ),
	);

	// do not modify below this line
	foreach ( $ranges as $range ) {
		$start_date = new DateTime( $range[0] );
		$end_date   = new DateTime( $range[1] );
		// include end date.
		$end_date->setTime( 0, 0, 1 );
		$period = new DatePeriod( $start_date, new DateInterval( 'P1D' ), $end_date );

		foreach ( $period as $date ) {
			$options['exceptions'][] = $date->format( 'm/d/Y' );
		}
	}

	$options['exceptionMode'] = 'disable';

	return $options;
}

Comments

  1. FIQRI ZAKARIA
    FIQRI ZAKARIA October 21, 2025 at 1:47 am

    How can I create and use a {weekends_minus_exceptions} and {weedayss_minus_exceptions} merge tag in Gravity Forms that automatically counts the number of weekend and weekday days between a Start Date and End Date, while excluding any dates listed as exceptions? The exception dates already selected in Start Date and End Date date picker.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff October 21, 2025 at 4:24 am

      Hi Fiqri,

      We don’t currently have a built-in solution for this, but it may be possible to achieve with a custom snippet. Our Pro license includes support for minor customizations, so if you have a Pro license, please submit a ticket we can take a closer look and assist you with the custom snippet.

      Best,

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.