Description

Filters the date field formats available for the Date Picker in the form builder.

Parameters

$date_formats
(array) (Required) Date format options.

Source

wpforms/pro/includes/fields/class-date-time.php

More Information

The wpforms_datetime_date_formats filter is applied to an array containing format options for date fields. These options are provided within the form builder when using the Date Picker option.

This filter can be used to add additional format options. The format will determine how date field selections are displayed to the user, how dates appear in entries and notifications, and also how date field selections appear within the database.

Default date format options include:

  • m/d/Y: 01/31/2019
  • d/m/Y: 31/01/2019
  • F j, Y: January 31, 2019

Please see the PHP date reference for additional format options.

Examples

In our example below, we’re keeping all the default date options but adding a new one that will look like this:
Tuesday 27th of August 2019 using the l jS \of F Y.

/**
 * Filters the date field formats available for the Date Picker in the form builder.
 * 
 * @link   https://wpforms.com/developers/wpforms_datetime_date_formats/
 *
 * @param  array $date_formats
 * @return array
 */
function wpf_dev_datetime_date_formats( $date_formats ) {

	$date_formats = array(
	'm/d/Y'  => 'm/d/Y',
	'd/m/Y'  => 'd/m/Y',
	'F j, Y' => 'F j, Y',
	'l jS \of F Y' => 'l jS \of F Y',
	);    
	return $date_formats;

}

add_filter( 'wpforms_datetime_date_formats', 'wpf_dev_datetime_date_formats', 10, 1 );

Snippet Reference: How to Create Additional Formats for the Date Field