Description

The wpforms_datetime_date_formats filters the date field formats available for the Date Picker in the form builder.

Parameters

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

Source

wpforms/includes/functions/data-presets.php

More Information

The 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 27 of August 2019 using the l j \of F Y.

Notice in the snippet we’re escaping the word of with a backslash (\).

/**
 * 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 $formats Date format options.
 * @return array
 */

function wpf_dev_date_field_formats( $formats ) {
 
    // Item key is JS date character - see https://flatpickr.js.org/formatting/
    // Item value is in PHP format - see http://php.net/manual/en/function.date.php
 
    // Adds new format Monday, 20th of December 2021
    $formats[ 'l, J \of F Y' ] = 'l, jS \of F Y';
 
    return $formats;
}
 
add_filter( 'wpforms_datetime_date_formats', 'wpf_dev_date_field_formats', 10, 1 );


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