---
title: "MONTHS_BETWEEN"
description: "The MONTHS_BETWEEN SQL functions gets the number of months between two dates."
language: en
source_language: en
translation_state: complete
canonical: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/sql-functions/months-between
original: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/sql-functions/months-between
updated: 2026-08-09T00:00:00Z
license: https://documentation.invantive.eu/en/
---

## Syntax
```mermaid
%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    Start((START)) --> MONTHS_BETWEEN[MONTHS_BETWEEN]:::quoted
    MONTHS_BETWEEN --> End((END))
```

## Purpose
The `MONTHS_BETWEEN` SQL functions gets the number of months between two dates. The fractional part is determined using a 30-day month length.

Parameters:
- Date 1 (`datetime`): first date.
- Date 2 (`datetime`): second date.

Returns: A `decimal` with the number of months and fractional part. Negative when date 2 is before date 1. Positive otherwise.

## Examples
The following example retrieves the number of months between January 1, 2017 and January 16, 2017:
```sql
select months_between(to_date('20170101', 'YYYYMMDD'), to_date('20170116', 'YYYYMMDD'))

-------------------
0.5
```
The following example retrieves the number of months between January 16, 2017 and January 1, 2017; the second date is before the first date:
```sql
select months_between(to_date('20170116', 'YYYYMMDD'), to_date('20170101', 'YYYYMMDD'))

-------------------
-0.5
```