# Number of months between two dates

**URL:** <https://discourse.julialang.org/t/number-of-months-between-two-dates/42128>\
**Category:** General Usage\
**Created:** [June 26, 2020, 8:50pm UTC](https://discourse.julialang.org/t/number-of-months-between-two-dates/42128 "2020-06-26T20:50:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atteson](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@atteson](https://discourse.julialang.org/u/atteson)\
**Post date:** [June 26, 2020, 8:50pm UTC](https://discourse.julialang.org/t/number-of-months-between-two-dates/42128/1 "2020-06-26T20:50:02Z")

</div>

Is there a convenient way to calculate the number of months between two dates? I can’t seem to find anything in the Dates package.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 27, 2020, 7:25am UTC](https://discourse.julialang.org/t/number-of-months-between-two-dates/42128/2 "2020-06-27T07:25:22Z")

</div>

I am not sure the question is well-defined, as months do not have a uniform length.

One convention I am aware of is using days, then dividing by `365.25/12 == 30.4375` (to account for leap years).

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 27, 2020, 8:25am UTC](https://discourse.julialang.org/t/number-of-months-between-two-dates/42128/3 "2020-06-27T08:25:38Z")

</div>

One simple way is

```julia
julia> using Dates

julia> start_date = Date(2019, 6, 27)
2019-06-27

julia> end_date = Date(2020, 6, 27)
2020-06-27

julia> length(start_date:Month(1):end_date)
13

```

(maybe requires some adjustment depending on how you want to deal with partial months, or whether the above should return 12 rather than 13 etc)
