• Resolved Ben Dunkle

    (@empireoflight)


    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Ben Dunkle

    (@empireoflight)

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

    $postid=$post->ID;
    $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!

    cdyerkes

    (@cdyerkes)

    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 :]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Custom Field Template] How to change the dateformat?’ is closed to new replies.