Number of quarters between 2 dates

Question:

Let say I have 2 dates in below format

date1 = '2020Q1'
date2 = '2022Q4'

I want to calculate number of quarter between these 2 dates as integer.

Is there any method available to perform this?

Asked By: Bogaso

||

Answers:

I would use pandas for this

import pandas as pd

print(len(pd.date_range('2020Q1', '2022Q4', freq="Q")))  # -> 11
Answered By: Joran Beasley
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.