Select Page

Formidable Forms [date] shortcode is used to get the current date. If a date relative to the current date is required, the offset attribute can be used.
e.g. [date offset='+3 weeks'] will return the date three weeks from today.

However, this is not true when a date field value is displayed using [x] shortcode where x is the field id or key. The [x] shortcode doesn’t support the offset attribute. But it is very easy to extend it with a few lines of custom code.

Here are some examples for a date field with id 123

[123 offset='+2 weeks']
[123 offset='-1 month']
[123 offset='+1 year 3 weeks']
[123 offset='Next Monday']
[123 offset='Last Friday']
[123 offset='First day of this month']
[123 offset='Last day of next month']

The offset attribute can be used together with format attribute which is already supported by Formidable.
e.g. [123 offset='+2 weeks' format='m/d/Y']

Add the following code to your functions.php or use Code Snippet plugin to enable this functionality.

add_filter('frmpro_fields_replace_shortcodes', 'frm_city_date_offset', 10, 4);
function frm_city_date_offset( $replace_with, $tag, $atts, $field ) {
    if ($field->type == 'date' and isset($atts['offset']) and $replace_with) {
		$replace_with = date('Y-m-d', strtotime($replace_with . $atts['offset']));
    return $replace_with;