YEAR_MONTH

YEAR_MONTH is a type of data in SQL that allows storing of the year and month only, not including information about the day or time. This data type is particularly useful for grouping and reporting purposes where the specific day or time is not a major concern.

Example

SELECT EXTRACT(YEAR_MONTH FROM '2021-05-27 01:23:45') as ExtractedYearMonth;

Output

+-------------------+
| ExtractedYearMonth|
+-------------------+
| 202105|
+-------------------+

Explanation

The EXTRACT function with YEAR_MONTH is used to retrieve the year and month as a decimal format (YYYYMM) from a specified date. Here, ‘2021-05-27 01:23:45’ was provided as the date, which returned ‘202105’ as the output.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.