• I have a date format problem with this code in my theme:
    where there is $ row-> eventdate it prints out the date from the database in the format as 05-06-2013, but I would like to reverse it in 2013-06-05 this is possible with a function php into the loop?

    <?php
    if ( in_category('Biglietti concerti') ) {
    
         echo '<h2 class="heading" style="text-align: center;">';echo "Date concerti ".get_the_title()." ".get_the_time('Y')."</h2>";
    
         $sql  = "SELECT * FROM wp_events where name  =  '".get_the_title()."' order by eventdate asc ";
         $result = $wpdb->get_results( $sql );
    
         if ( count($result) > 0 )
         {
    
             echo '<div class="date"><table><tbody>';
    
             foreach($result as $row)
             {
                 echo '<tr class="vevent">
                     <td><abbr class="dtstart" title="'.$row->eventdate.'T'.$row->time.'">'.$row->eventdate.'</abbr><abbr class="summary" title="'.get_the_title().'"></abbr></td>
                     <td><a href="'.get_permalink().'">'.$row->city.'</a></td>
                     <td><span class="location">'.$row->location.'</span></td>
                     <td><a href="#biglietti concerti">Biglietti</a></td>
                            </tr>
                            ';
            }
    
            echo '</tbody></table></div>' ;
    
         } else {
        ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code has now been permanently damaged by the forum’s parser.]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Try date('Y-m-d', strtotime($row->eventdate))

    This should work correctly as your “05-06-2013” input appears to be European format for June 5th 2013. If US format for May 6th 2013, replace the hyphens with slashes, as the US format input should be “05/06/2013”

    Of course, you can rearrange the output format ‘Y-m-d’ any way you like.

Viewing 1 replies (of 1 total)

The topic ‘reverse date time format in php’ is closed to new replies.