
- 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
In which format Year(2) or Year(4) MySQL will return the value of year from date ‘0000-00-00’?
Suppose if we have stored a date value as ‘0000-00-00’ in MySQL table then on extracting year value from such kind of date, MySQL will return 0. It would not be in either Year(2) or Year(4) format. To understand it we are using the following data from ‘detail_bday’ table −
mysql> Select * from detail_bday; +----+---------+------------+ | Sr | Name | Birth_Date | +----+---------+------------+ | 1 | Saurabh | 1990-05-12 | | 2 | Raman | 1993-06-11 | | 3 | Gaurav | 1984-01-17 | | 4 | Rahul | 1993-06-11 | | 5 | Sonia | 1993-11-31 | | 6 | Ram | 0000-00-00 | +----+---------+------------+ 6 rows in set (0.00 sec)
Now the following query will try to fetch the year value from a date ‘0000-00-00’ −
mysql> Select Year(Birth_date) from detail_bday Where Name = 'Ram'; +------------------+ | Year(Birth_date) | +------------------+ | 0 | +------------------+ 1 row in set (0.00 sec)
The above result set shows that MySQL returns 0 instead of giving the value in the format Year(2) or Year(4).
- Related Articles
- How can I store ‘0000-00-00’ as a date in MySQL?
- MySQL extract year from date format?
- Format date in MySQL to return MonthName and Year?
- MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?
- Create MySQL datetime column with default 0000-00-00?
- MySQL query to select date from 00:00 to today’s date
- What is the difference between YEAR(2) and YEAR(4) in MySQL?
- Format MySQL date and convert to year-month-day
- Changing year in MySQL date?
- Get the correct century from 2-digit year date value - JavaScript?
- Create date from day, month, year fields in MySQL?
- How MySQL use YEAR data type to store year value in a table?
- Format Year in yy format in Java
- Format Year in yyyy format in Java
- Ignoring the year in MySQL Query with date range?

Advertisements