- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
- Delete a specific record on the basis of EmployeeId in MySQL
- Get beginning and end date from a specific year in MySQL
- MySQL query to decrease the value of a specific record to zero?
- Extract the Day / Month / Year from a Timestamp in PHP MySQL?
- How to get a specific column record from SELECT query in MySQL?
- MySQL query to fetch record by year
- Display only a specific duplicate record in MySQL
- Get specific value of cell in MySQL
- MySQL CONCAT a specific column value with the corresponding record
- MySQL query to place a specific record on the top
- Implement specific record ordering with MySQL
- Get digits from a record in MySQL?
- How to select record except the lower value record against a specific value in MySQL?
- Find out the records of students with more than a specific score in MySQL?
- How do I exclude a specific record in MySQL?