Important
The SingleStore 9.1 release candidate (RC) is available now. It will be promoted to general availability (GA) soon and at that time it will be renamed to SingleStore 10.
In the interim, SingleStore 9.1 RC can be used to preview, evaluate, and provide feedback on the new and upcoming features in SingleStore 10, while SingleStore 9.0 is recommended for production workloads.
MONTHS_ BETWEEN
On this page
The MONTHS_ function subtracts to find the number of months between two dates.
Syntax
MONTHS_BETWEEN(date1, date2)Arguments
-
date1,date2: A valid date, datetime, or parsable date string.Only the date part is used.
Return Type
Integer.date1 or date2 is not a valid date, returns NULL.
Examples
SELECT MONTHS_BETWEEN(DATE('2017-03-01'), DATE('2017-01-01'));
+--------------------------------------------------------+
| MONTHS_BETWEEN(DATE('2017-03-01'), DATE('2017-01-01')) |
+--------------------------------------------------------+
| 2 |
+--------------------------------------------------------+If date1 is in the past, the function returns a negative result.
SELECT MONTHS_BETWEEN(DATE('2017-01-01'), DATE('2017-03-01'));
+--------------------------------------------------------+
| MONTHS_BETWEEN(DATE('2017-01-01'), DATE('2017-03-01')) |
+--------------------------------------------------------+
| -2 |
+--------------------------------------------------------+NOW() can be used as one of the parameters.
SELECT MONTHS_BETWEEN('2017-10-31',NOW());
+------------------------------------+
| MONTHS_BETWEEN('2017-10-31',now()) |
+------------------------------------+
| 2.741935483870968 |
+------------------------------------+Related Topics
Last modified: