Home Forums ACF PRO Change date format with jquery


Change date format with jquery

  • Hi, i need to change the date format from YYYYMMDD to jS F Y with jquery in Essential Grid plugin.

    I have custom date Meta used in the EssGrid from ACF but it always renders it as YYYYMMDD.

    How can i change this?

  • That is the format that ACF stores date in the DB. You either need to use an ACF function or filter the value being used by the other plugin. I don’t know how that other plugin works, but what you need to do is figure out how to filter the values that it’s displaying. You need to as them how to do that. Once you figure out how to do that

    $date = date('jS F Y', strtotime($value_from_db));
  • Thanks for the input John, I just cant figure out how the Plugin render the date at the moment, I’ve gone back to the free version of ACF as the EssGrid plugin renders the date correctly.

  • That is most likely because ACF4 let’s you set the storage format and the other plugin uses whatever is stored in the field. ACF5 does not have this option and stores the dates in a standard way that allows sorting by date field. You can only sort by dates it the order is year/month/day.

    You should talk the the developers of the other plugin and ask them is there is a way to filter the values of custom fields before they are displayed.

    Your other choice would be to create a separate field that holds the value that you want displayed.

    add_filter('acf/update_value/name=the_acf_date_field_name', 'store_date_field_in_displayable_format', 10, 3);
    function store_date_field_in_displayable_format($value, $post_id, $field) {
      if ($value) {
        $new_value = date('jS F Y', strtotime($value));
        update_post_meta($post_id, 'field_name_to_use_in_other_plugin', $new_value);
      return $value;

    field_name_to_use_in_other_plugin needs to be a unique field name and then you use that field name to set up the other plugin. Personally, I’d go with the first option, but I can’t really help you figure out how to use that other plugin since I’ve never used it.

  • Been on to the developers and they wrote a shortcode for me

    function getdatefromacf_shortcode( $atts ) {
    	// Attributes
    	extract($atts = shortcode_atts(
    			'postid' => '',
    			'metaid' => 'date_from'
    	return get_field($metaid, $postid);
    add_shortcode( 'getdatefromacf', 'getdatefromacf_shortcode' );
    [getdatefromacf metaid='date_to' postid=%post_id%]
    [getdatefromacf metaid='date_from' postid=%post_id%]

    It solves the problem

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Change date format with jquery’ is closed to new replies.