Updated on 2023-10-25 GMT+08:00

month

This function is used to return the month (from January to December) of a specified time.

Syntax

month(string date)

Parameters

Table 1 Parameter

Parameter

Mandatory

Type

Description

date

Yes

DATE

or

STRING

Date that needs to be processed

If the value is of the STRING type, the value must contain at least yyyy-mm-dd and cannot contain redundant strings.

The following formats are supported:

  • yyyy-mm-dd
  • yyyy-mm-dd hh:mi:ss
  • yyyy-mm-dd hh:mi:ss.ff3

Return Values

The return value is of the INT type.

  • If the value of date is not of the DATE or STRING type, the error message "data type mismatch" is displayed.
  • If the value of date is of the DATE or STRING type but is not in one of the supported formats, NULL is returned.
  • If the value of date is NULL, NULL is returned.

Example Code

The value 8 is returned.

select month('2023-08-10 10:54:00');

The value NULL is returned.

select month('20230810');

The value NULL is returned.

select month(null);