Viewing 4 reply threads
  • Author
    Posts
    • #8885
      Sara
      Participant

      Hello 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

    • #8888
      Sara
      Participant

      It’s ok, got it with the Unix timestamp… duh!
      Love this plugin btw, thanks for the great job 🙂

    • #8889
      Sara
      Participant

      Ok 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?

    • #8905
      Steve
      Keymaster

      What is the value you get from $date = get_post_meta($post->ID, 'date', true);

      • #8909
        Sara
        Participant

        Hi 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;
        
    • #8924
      Steve
      Keymaster

      Hi 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;
Viewing 4 reply threads
  • The topic ‘Date Picker – can't prettify date’ is closed to new replies.