Title: reverse date time format in php
Last modified: August 21, 2016

---

# reverse date time format in php

 *  [radiocono](https://wordpress.org/support/users/radiocono/)
 * (@radiocono)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/reverse-date-time-format-in-php/)
 * 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](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/reverse-date-time-format-in-php/#post-4190470)
 * 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.

## Tags

 * [date](https://wordpress.org/support/topic-tag/date/)
 * [date time](https://wordpress.org/support/topic-tag/date-time/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/reverse-date-time-format-in-php/#post-4190470)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
