Convert Entry Date Created to Datepicker Format

Convert entry’s “date_created” value from the database format (e.g. ISO 8601) to the datepicker format (e.g. m/d/Y) when populating into a Date field.

Code

Filename: gppa-entry-date-created-to-datepicker.php

<?php
/**
 * Gravity Perks // Populate Anything // Convert Entry Date Created to Datepicker Format
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * Convert entry's "date_created" value from the database format (e.g. ISO 8601) to the datepicker format (e.g. m/d/Y)
 * when populating into a Date field.
 */
add_filter( 'gppa_process_template_value', function ( $value, $field, $template_name, $populate, $object, $object_type, $objects, $template ) {
	if ( $template === 'date_created' && $field->get_input_type() === 'date' && $field->dateType === 'datepicker' ) {
		$value = date_format( date_create_from_format( 'Y-m-d H:i:s', $value ), 'm/d/Y' );
	}
	return $value;
}, 10, 8 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.