Custom Field Template
[resolved] How to change the dateformat? (3 posts)

  1. Ben Dunkle
    Posted 5 years ago #

    How can I change the startdate to use a different dateformat than yyyy/mm/dd? I'd like my dates to read June 11, for example, not 2011/07/11
    Thanks for any help.

  2. Ben Dunkle
    Posted 5 years ago #

    In case anyone needs this, here's what I did:

    $date = get_post_meta($postid, 'Concert Date', true);
    $dateparts=explode("/", $date);
    $date = date( 'F j', mktime(0, 0, 0, $dateparts[0], $dateparts[1]) );

    now when I echo $date I get it in the format I want!

  3. cdyerkes
    Posted 5 years ago #

    Thanks for this code. I adapted it to use an array so I could use the if else statements in case you didn't have a value stored in the date field.

    <?php // Get all custom fields attached to this post and store them in an array
      $custom_fields = base_get_all_custom_fields();
      $dateparts = explode("/", $custom_fields['Effective Date']);
      $datedisplay = date( 'F j, Y', mktime(0, 0, 0, $dateparts[0], $dateparts[1]) ); ?>

    then insert this into the area of your template you want the date to display:

    <?php if( !empty($custom_fields['Effective Date']) ) { ?><?php echo $datedisplay; ?><?php } ?>

    Because the if( !empty()) is used...it will check to see if the field is empty, and if it is, it won't display the date.

    I'm sure there is an easier way, but it works for me :]

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Field Template
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic