 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert DATE timestamp to return the month number
To return only the month number, 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 month number −
mysql> select date_format(ArrivalDate,'%m') as MonthName from DemoTable1999;
This will produce the following output −
+-----------+ | MonthName | +-----------+ | 01 | | 12 | | 10 | +-----------+ 3 rows in set (0.00 sec)
Advertisements
 