Home > Database > Mysql Tutorial > body text

In which format Year(2) or Year(4) will MySQL return the year value starting from the date '0000-00-00'?

WBOY
Release: 2023-09-19 14:57:14
forward
640 people have browsed it

In which format Year(2) or Year(4) will MySQL return the year value starting from the date 0000-00-00?

Suppose if we store a date value "0000-00-00" in a MySQL table, then MySQL will return 0 when extracting the year value from such a date. It will not be in Year(2) or Year(4) format. To understand it, we use the following data from the "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)
Copy after login

Now the following query will try to get the year value from the 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)
Copy after login

The above result The set shows that MySQL returns 0 instead of giving the value in Year(2) or Year(4) format.

The above is the detailed content of In which format Year(2) or Year(4) will MySQL return the year value starting from the date '0000-00-00'?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!