• I have a date field displayed in the sidebar with the following code.

    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'ndeath', true);

    The date is displaying Year/Month/Day. How do I go about changing this to Month Day, Year or Month/Day/Year?

    Thank you!

Viewing 1 replies (of 1 total)
  • Hi Sjbmaine
    I was looking for my problem solution that saw your question.
    I’m using same and as I think custom field is in string format you need to rearrange it’s characters in order you want.(or just edit it’s value in post maybe). for example if it’s in this format: 2012/05/01
    then this is a string with 10 character (character number 0 is 2 and number 9 is 1) and using below code will convert it to 05/01/2012

    $date1 = get_post_meta($post->ID, ‘ndeath’, true);
    $date2=substr ($date1,5 ,2).’/’.substr ($date1,8 ,2).’/’.substr ($date,0 ,4);

    substr($date1,5,2) for example gives you a sub string of $date1 with length 2 starting from character 5 that is 0 so it would be 05.

    But my problem is comparing this date with current date, as this is a string and not in date type and when I get the current date I cant compare them, as I see strange behaviors when I do , like, 1/05/2012 would be less than 23/04/2012 so I need to change it first to date format them compare I think, hope someone gives me a help. ??

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Just Custom Fields] Changing the date format’ is closed to new replies.