MySQL MONTH() Function

MySQL | MONTH() Function: Learn about the MONTH() function, how it works, its usages, syntax, and examples.
Submitted by Apurva Mathur, on October 10, 2022

MONTH() Function

The MONTH() function helps us to get the month part from any datetime value. It fetches the month from the date and then displays it as a result.

MONTH() Syntax

SELECT MONTH('datetime value');

MONTH() Parameter(s)

  • It takes only one parameter which is datetime value.

MONTH() Return Value

As a result, it will display the month part from the time that you have provided.

MySQL MONTH() Function Example 1

SELECT MONTH('2002-5-18');
Example 1: MySQL MONTH() Function

MySQL MONTH() Function Example 2

SELECT MONTH('2012-9-08 12:09:08');
Example 2: MySQL MONTH() Function

But if you will provide the date which is not valid then in such case it will show you NULL.

MySQL MONTH() Function Example 3

SELECT MONTH('2012-69-08');
Example 2: MySQL MONTH() Function

In the above example, we can see that the month has a 69 value which is not valid therefore it displays NULL.




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.