
- 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
Get the record of a specific year out of timestamp in MySQL?
You can get year out of timestamp using YEAR() function. The syntax is as follows −
SELECT yourColumnName FROM yourTableName WHERE YEAR(yourTimestampColumnName)='yourYearValue’';
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table getYearOut -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(10), -> yourTimestamp timestamp default current_timestamp, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.56 sec)
Insert some records in the table using INSERT command−
mysql> insert into getYearOut(Name,yourTimestamp) values('John',now()); Query OK, 1 row affected (0.26 sec) mysql> insert into getYearOut(Name,yourTimestamp) values('Carol','2018-09-23 17:34:44'); Query OK, 1 row affected (0.38 sec) mysql> insert into getYearOut(Name,yourTimestamp) values('Bob','2016-05-12 16:12:34'); Query OK, 1 row affected (0.43 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from getYearOut;
The following is the output −
+----+-------+---------------------+ | Id | Name | yourTimestamp | +----+-------+---------------------+ | 1 | John | 2019-02-05 11:46:11 | | 2 | Carol | 2018-09-23 17:34:44 | | 3 | Bob | 2016-05-12 16:12:34 | +----+-------+---------------------+ 3 rows in set (0.00 sec)
Here is the query to get year out of timestamp. If your table has a specific year, then the query is as follows −
mysql> select Id, Name from getYearOut where year(yourTimestamp)='2019';
The following is the output displaying the record of the year 2019 −
+----+-------+ | Id | Name | +----+-------+ | 1 | John + 1 row in set (0.00 sec)
- Related Articles
- Delete a specific record on the basis of EmployeeId in MySQL
- Get beginning and end date from a specific year in MySQL
- How to get a specific column record from SELECT query in MySQL?
- Extract the Day / Month / Year from a Timestamp in PHP MySQL?
- Display only a specific duplicate record in MySQL
- MySQL query to decrease the value of a specific record to zero?
- MySQL query to fetch record by year
- How do I exclude a specific record in MySQL?
- How to select record except the lower value record against a specific value in MySQL?
- Get digits from a record in MySQL?
- Implement specific record ordering with MySQL
- MySQL CONCAT a specific column value with the corresponding record
- MySQL query to place a specific record on the top
- Get only the date in timestamp in MySQL?
- Get specific value of cell in MySQL

Advertisements