Gintoki
Gintoki

Reputation: 142

MySQL doesent sort by date

I'm trying to run this query:

$query = "SELECT * FROM `official_holiday` ORDER BY `official_holiday`.`date` desc";

I even generated the query with PHPMyAdmin just to be sure its correct. I dont why it does not order at all and just takes the dates as they are in the DB.

How can I order by date? I just want to echo the results with the smallest date first from the fetched result array.

Thanks in advance

E// enter image description here

Upvotes: 0

Views: 44

Answers (2)

OllyBarca
OllyBarca

Reputation: 1531

SELECT * FROM `official_holiday` ORDER BY date DESC.

This should work, as long as your dates are stored in the correct format.

Nice and simple.

Upvotes: 0

Niranjan N Raju
Niranjan N Raju

Reputation: 11987

Change your query like this

SELECT * FROM `official_holiday` ORDER BY DATE(`official_holiday`.`date`) desc.

It will work fine.

Upvotes: 1

Related Questions