phpmysqlsql-order-bychronological

Chronologically order a SELECT query's results by month name


I've a table named gst that contain

CREATE TABLE gst (
    gst_id INT PRIMARY KEY AUTO_INCREMENT,
    month VARCHAR(9) NOT NULL,
    price INT NOT NULL
);
INSERT INTO gst 
(gst_id,    month, price)
  VALUES
(     7, February,   3),
(    16,  January,   5)
(    17,    April,   7),
(    18,    March,   2),

I want to display a result in the order of month (ie january, february, march.........):

16             January         5
 7             February           3
18             March             2
17             April             7

How can I write the sql query?


Solution

  • Try this....

    SELECT DATE_FORMAT(date_col, '%M') as month FROM table ORDER BY month
    

    Try this link also...

    Date-Time Functions