1

I am using the More Fields plugin which gives me the ability to create a date formatted YYYY/mm/dd and I want to convert that to be shown like: February 11, 2011

Is this possible?

3 Answers 3

7

Do you have issue with exactly converting or retrieval? Converting is trivial and is plain PHP:

date('F j, Y', strtotime($date));

For more complex and WordPress-specific way with localization support see date_i18n() function.

6
  • Rarst, this looks right but I am having trouble making it work 100%. $date = meta('event_date'); echo date('F j, Y', strtotime($date)); returns January 1 1970.... ideas?
    – tjsherrill
    Commented Mar 15, 2011 at 22:35
  • @tjsherrill ehm, I don't think meta() is native function?.. Are you sure you get sane string value in $date?
    – Rarst
    Commented Mar 15, 2011 at 22:40
  • I got it, meta(); is a template tag provided by the more-fields plugin. I simply used get_post_meta and it works great. thanks
    – tjsherrill
    Commented Mar 18, 2011 at 15:28
  • This isn't working for me. My custom field is "date-time-last" $date = get_post_meta('date-time-last'); echo date('l jS F Y', strtotime($date));
    – Pete
    Commented Apr 11, 2016 at 8:59
  • @Pete check the values you are getting and stuff, "isn't working" is a little vague. :)
    – Rarst
    Commented Apr 11, 2016 at 9:29
2

This works for me (inside the loop)...

<?php $date = get_post_meta($post->ID, 'CUSTOM-FIELD-HERE', true); if($date != ''){echo date("l jS F Y", strtotime($date));} ?>
0
<?php
$date = '2000/10/28';
$a = preg_split ( '/\//', $date );
echo date('F j, Y', mktime( 0, 0, 0, $a[1], $a[2], $a[0] ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.