[Update] Formidable Forms now supports “offset” attribute. So this custom code is no longer required.
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']
Replace 123 with your field ID.
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; }
Awesome post! Keep up the great work! 🙂
Great post, unfortunately it is not working right now, maybe an update broke it?
Hi Michael,
I have tested it with the latest WordPress and Formidable forms. It works for me. Could you share more details so I can help you find out the issue?
Doesn’t seem to work for me.
The default date offset also only works when I use double quotation marks around the offset (“+1 year”), not when I use single marks (‘).
I’m using WordPress 5.6 (multisite) and the latest Formidable (4.09.04).
It just shows your shortcode in the date field.
It’s activated in Code Snippets (2.14.0).
Hi Damien,
Formidable now supports “offset” attribute. So this custom code is no longer required.
https://formidableforms.com/knowledgebase/date/#kb-display-date-fields
is it possible to use [date offset=’First day of next month’]? Or is there some tweak I need to do to make that work? I tried it with single quotes and double quotes and neither work. It just shows me today’s date.
it doesn’t make sense that you can do an offset for the “last day of next month” but not the first day.
disregard my previous comment – (kinda) it should have been posted on the cheat sheet post.
the question still stands though, i put the short code in the form builder [date offset=’First day of next month’] and it just shows me today’s date. not the first day of next month, which doesn’t make sense if you can put in a short code for the last day of next month.