Change datepicker date format after form submission [RESOLVED]

Please can someone help me code a function to change the date format of a datepicker field after form submission. I would like to change the format from the default ‘dd/mm/yy’ to ‘d MM, yy’ so when admin views the form entries they will see ‘17 February, 2020’ instead of ‘17/02/2020’.

I tried adding a js script into the form itself, but the form doesn’t validate because it’s expecting the format ‘dd/mm/yy’. I would like the format to be changed after validation (eg, using gform_pre_submission).


You can use the filter to modify a value before it is saved in the entry. You would need to create the date functions to transform the date format according to your needs. The code would look something like this:

// submitted date always looks like this: 2020-02-14 
// no matter what datepicker format is used for the field
add_filter( "gform_save_field_value", "transform_date", 10, 4 );
function transform_date( $value, $entry, $field, $form ){
  // set the form ID and field ID here
  if ( $form['id'] === 495 && $field['id'] === 1 ) {
    GFCommon::log_debug( __METHOD__ . "(): Value is {$value}." );
    $timestamp = strtotime ( $value );
    GFCommon::log_debug( __METHOD__ . "(): Timestamp is {$timestamp}." );
    $value = date ( 'F d. Y', $timestamp );
    GFCommon::log_debug( __METHOD__ . "(): Modified Value is {$value}." );
  // return the value, modified or not
  return $value;

This is PHP code which can go into your theme functions.php file or a custom functionality plugin if you are using one. Change the form ID from 495 and field ID from 1 to match your form and give that a test. This worked for me. Let me know if you have any questions.

Thank you, Chris, I’ll see if I can implement this.

Hey Chris

Your code worked perfectly, many thanks!

1 Like

You’re welcome!

© 2008 - 2021. Gravity Forms is a project by Rocketgenius Inc.