Format date from database within Codeigniter

0 votes

I am using Codeigniter i have this code within a view, however the format of the date within the database is YYYY-MM-DD i am wanting to changing it to DD-MM-YYYY. I am unable to change it within phpMyAdmin so i am looking for a solution in php.

"Date" is a column within my database just to cause confusion.

$query = $this->db->query('SELECT Date, Home, HomeScore, AwayScore, Away FROM Results');

        foreach ($query->result_array() as $row)
            echo '<div class="col-md-4 col-sm-12"><h3>';
            echo $row['Date'];
            echo "</h3><h4>Premier League</h4><h5>";
            echo $row['Home'];
            echo "</h5><span>";
            echo $row['HomeScore'];
            echo "</span><span>";
            echo $row['AwayScore'];
            echo "</span><h5>";
            echo $row['Away'];
            echo "</h5></div>";
asked Jan 24 by Navarra (330 points)

2 Answers

+1 vote

You should try this one:

$date = $row['Date'];
echo date("d/m/Y",strtotime($date));
answered Jan 24 by domingez (950 points)
Awesome! Thank you.
You welcome:)
0 votes

Try like this.The DATE_FORMAT() function is used to display date/time data in different formats.

SELECT DATE_FORMAT(Date,'%d-%m-%Y'), Home, HomeScore, AwayScore, Away FROM Results

For more see here

answered Jan 24 by Max (140 points)
Welcome to Ask.CodeIgniter, where you can ask questions and receive answers from other members of the community.
 | Mediacode Theme
Powered by Question2Answer