Tutorial Gateway

  • C Language
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • Js

MySQL Year Function

by suresh

MySQL Year function is one of the Date Function, which is used to return the Year from the given date. This function returns value range from 1000 to 9999.

In this article, we will show you, How to use this MySQL Year function to get the Year from an expression with example.

MySQL Year Syntax

The basic syntax of the Year() Function in MySQL is as shown below:

YEAR(date or expression);

TIP: This MySQL Year function returns 0, if the date argument is 0000-00-00 or say, zero date part.

MySQL Year function Example

The below shown queries helps you understand the basic use of Year function. Here, we are returning the Year value from the date expression, and the Date and time expression.

SELECT YEAR('2016-11-25');

SELECT YEAR('2018-10-22 01:09:22');

OUTPUT

MYSQL Year Function 2

Let us see another example of MySQL Year function. Here, we are extracting Year from the current date and time returned by the Now() function.

SELECT YEAR(NOW());

OUTPUT

MYSQL Year Function 3

MySQL Year Function Example 2

The following query will show you, what happens when we try to extract the year from a date or date and time in string format.

SELECT YEAR('2016-11-44');

SELECT YEAR(NOW() + 5);

SELECT YEAR(0);

OUTPUT

MYSQL Year Function 4

From the above screenshot, YEAR(‘2016-11-44’); is returning NULL. Because, it is an invalid date.

Last statement YEAR(0) means, we are trying to extract Year from a zero date part. That’s why, it returns NULL.

Thank You for Visiting Our Blog

Placed Under: MySQL

Trending Posts

Gantt Chart in Tableau

Excel Connection Manager in SSIS

C Program to find Volume and Surface Area of a Cone

JavaScript POW

C round function

SQL Rename Column

Tableau Conversion Functions

Python Program to find Total Average and Percentage of Five Subjects

Tableau Grouping

MySQL COALESCE Function

  • C Programs
  • Java Programs
  • SQL FAQ’s
  • Python Programs
  • SSIS
  • Tableau
  • JavaScript

Copyright © 2019 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy