- This topic has 5 replies, 2 voices, and was last updated 3 years, 9 months ago by
Steve.
-
AuthorPosts
-
-
May 2, 2018 at 5:55 am #8885
SaraParticipantHello there,
I’m new to Piklist and WP php’s magic, so please forgive my naivety…
I have a “event” CPT (like many others on this forum) and I’m trying to get the date displayed but with no luck so far.<?php $date = get_post_meta($post->ID, 'date', true); $new_date = date("Y-m-d", strtotime($date)); echo $date; // 16/09/2019 echo $new_date; // 1970-01-01 ?>I also tried to create a new DateTime() but it breaks the code
<?php $date = get_post_meta($post->ID, 'date', true); $new_date = new DateTime($date); echo $new_date->format('Y'); ?>Could you please give me some hints, I’m completely out of ideas.
Thank you -
May 2, 2018 at 9:52 am #8888
SaraParticipantIt’s ok, got it with the Unix timestamp… duh!
Love this plugin btw, thanks for the great job 🙂 -
May 2, 2018 at 10:40 am #8889
SaraParticipantOk spoke too soon…
I still can’t strttotime my date without it being reset to 1970.
Tried to edit the value and dateForat, nothing helped.Anyone?
-
May 3, 2018 at 5:41 pm #8905
SteveKeymasterWhat is the value you get from
$date = get_post_meta($post->ID, 'date', true);-
May 7, 2018 at 3:11 am #8909
SaraParticipantHi Steve,
Sorry for being late to thank you for your answer.
I got it to work by setting the Unix timestamp to default, updating my dates in the posts, and finally using the WP internationalization.$date = get_post_meta($post->ID, 'event_date', true); $new_date = date_i18n("d M Y", strtotime($date)); echo $new_date;
-
-
May 8, 2018 at 3:40 pm #8924
SteveKeymasterHi Sara– Glad you got it working.
Going to post your code snippet so others can benefit:
$date = get_post_meta($post->ID, 'event_date', true); $new_date = date_i18n("d M Y", strtotime($date)); echo $new_date;
-
-
AuthorPosts
- The topic ‘Date Picker – can't prettify date’ is closed to new replies.