Syntax error Convert DATE timestamp to return only the month name in MySQL

Convert DATE timestamp to return only the month name in MySQL



To return only the month name, you can use DATE_FORMAT() −

mysql> create table DemoTable1999
(
   ArrivalDate timestamp
);
Query OK, 0 rows affected (0.66 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1999 values('2019-01-01 12:34:00');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable1999 values('2019-12-31 10:04:00');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable1999 values('2018-10-11 04:04:30');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1999;

This will produce the following output −

+---------------------+
| ArrivalDate         |
+---------------------+
| 2019-01-01 12:34:00 |
| 2019-12-31 10:04:00 |
| 2018-10-11 04:04:30 |
+---------------------+
3 rows in set (0.00 sec)

Here is the query to return the month name −

mysql> select date_format(ArrivalDate,'%M') as MonthName from DemoTable1999;

This will produce the following output −

+-----------+
| MonthName |
+-----------+
| January   |
| December  |
| October   |
+-----------+
3 rows in set (0.05 sec)
Updated on: 2020-01-02T05:35:56+05:30

218 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements