WordPress.org

Ready to get started?Download WordPress

Forums

Formatting date in echo get_post_meta (3 posts)

  1. swcomm
    Member
    Posted 3 years ago #

    I'm using:

    $has_my_meta = get_post_meta( $post->ID, 'StartDate,EndDate',true );
    if( $has_my_meta )
    $with_meta[] = $post->ID?>

    To grab event start and end dates that are stored as custom fields, and then outputting the date with echo get_post_meta, but I'm not having a lot of luck formatting the date output. Dates are stored as YYYY-MM-DD. I'd like the dates to display as n/j/Y or even as M/j/Y. What am I missing?

    Thanks in advance

  2. robthecomputerguy
    Member
    Posted 3 years ago #

    Did you ever get an answer to this question, because I have it too.

  3. vtxyzzy
    Member
    Posted 3 years ago #

    In your example, get_post_meta will only accept a single Custom Field name. Try something like this:

    $start_date = get_post_meta( $post->ID, 'StartDate', true);
    $new_format_start = date('M/j/Y',strtotime($start_date));

Topic Closed

This topic has been closed to new replies.

About this Topic