WordPress meta data as unix timestamp, how to convert?

This is the i normally get meta data from wordpress articles (CODE 1):

<?php echo get_post_meta($post->ID, 'evcal_srow', true); ?>

now the “evcal_srow” is UNIX timestamp that shows me something like: “1404187200”. Now i have to convert it somehow bu i don’t know how to write that? i havetried this (CODE 2:):

Read More
<?php 
     $metakey='evcal_srow'; 
     $startzeit=$wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey));
          if($startzeit){
          foreach($startzeit as $evcal_srow){
          echo "<div class='datum'>".gmdate("d.m.Y", $evcal_srow)."</div><div class='uhrzeit'>".gmdate("H:i", $evcal_srow)."</div>";
      }
  } 
?>

but it always gives me ALL meta data of EVERY article. the first code (CODE 1) above gets the ID but only gives me the unix timestamp, CODE 2 gives me the correct date and time but shows all metadata he can find in the tables … i need to show only the metadata that belongs to the article.

Related posts

Leave a Reply

1 comment

  1. found a solution:

    <?php
        $ts = get_post_meta($post->ID, 'evcal_srow', true);
        $date = new DateTime("@$ts");
        echo "<div class='datum'>".$date->format('d.m.Y')."</div><div class='uhrzeit'>".$date->format('H:i')."</div>";
    ?>