• Resolved borisj

    (@borisj)


    Hi,

    I have a custom field date with the value structure YYYY-MM-DD (e.g. 2018-03-15).

    Now I want to output this in an appropriate date format (e.g. l jS F Y).

    Can someone help me with this?

    Boris

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor zymeth25

    (@zymeth25)

    First create a custom template.

    In the template file, use this code:

    
    $date = get_post_meta( $post->ID, '[your custom field name]', true );
    $dateTime = DateTime::createFromFormat("Y-m-d", $date);
    

    Remember to replace [your custom field name] with an actual custom field name.

    Now you can use the dateTime object to output your date wherever you want, in whatever format you want. Just call $dateTime->format('l jS F Y');

    Hope it helps.

    • This reply was modified 6 years, 8 months ago by zymeth25.
    • This reply was modified 6 years, 8 months ago by zymeth25.
    Thread Starter borisj

    (@borisj)

    Thank you very much for your quick support. Finally I did it.

    As for the template just let me mention that I had to add the missing code for the “no_posts_text” value.

    Plugin Contributor zymeth25

    (@zymeth25)

    Yes, we know it is missing. It should be added in future releases.

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Converting custom field date to date format’ is closed to new replies.