
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to convert timestamp to month?
To convert timestamp to month, use the FROM_UNIXTIME() method as in the below syntax −
select month(from_unixtime(yourColumnName)) from yourTableName;
Let us first create a table −
mysql> create table DemoTable1457 -> ( -> Value bigint -> ); Query OK, 0 rows affected (0.85 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1457 values(1570207117); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable1457 values(1548947534); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1457 values(1575213134); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1457;
This will produce the following output −
+------------+ | Value | +------------+ | 1570207117 | | 1548947534 | | 1575213134 | +------------+ 3 rows in set (0.00 sec)
Following is the query to convert timestamp to month −
mysql> select month(from_unixtime(Value)) from DemoTable1457;
This will produce the following output −
+-----------------------------+ | month(from_unixtime(Value)) | +-----------------------------+ | 10 | | 1 | | 12 | +-----------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Convert DATE timestamp to return only the month name in MySQL
- Convert MySQL timestamp to UNIX Timestamp?
- Convert DATE timestamp to return the month number
- MySQL query to convert a string into a month (Number)?
- How to convert from Unix timestamp to MySQL timestamp value?
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- MySQL query to select date from timestamp?
- How to convert MySQL datetime to Unix timestamp?
- How to convert timestamp to datetime in MySQL?
- Convert MySQL Unix-Timestamp format to date format?
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- Convert string (varchar) to timestamp format in MySQL?
- MySQL query to sort by both timestamp and enum?
- MySQL query to update only month in date?
- Convert MM/DD/YY to Unix timestamp in MySQL?

Advertisements