You can solve this as below in data frame API
Creating a sample data frame
df = spark.createDataFrame([["123","2012-01-01","2012-10-01"],['234', '2012-01-01', '2012-05-01'],["345","2012-01-01","2012-11-01"]], ("age","date_active", "date_end"))
+---+-----------+----------+
|age|date_active| date_end|
+---+-----------+----------+
|123| 2012-01-01|2012-10-01|
|234| 2012-01-01|2012-05-01|
|345| 2012-01-01|2012-11-01|
+---+-----------+----------+
Changing data type from string to timestamp
df = df.withColumn('date_active', df['date_active'].cast('timestamp'))\
.withColumn('date_end', df['date_end'].cast('timestamp'))
Using below code adding the month column
from pyspark.sql import functions as f
df.withColumn('month_diff', f.months_between('date_end', 'date_active')).withColumn("repeat", f.expr("split(repeat(',', month_diff), ',')"))\
.select("*", f.posexplode("repeat").alias("date", "val")).withColumn("date", f.expr("add_months(date_active, date)"))\
.withColumn('month', f.date_format('date','MMM')).select(['age', 'date_active', 'date_end', 'month']).show()
---+-----------+----------+-----+
|age|date_active| date_end|month|
+---+-----------+----------+-----+
|123| 2012-01-01|2012-10-01| Jan|
|123| 2012-01-01|2012-10-01| Feb|
|123| 2012-01-01|2012-10-01| Mar|
|123| 2012-01-01|2012-10-01| Apr|
|123| 2012-01-01|2012-10-01| May|
|123| 2012-01-01|2012-10-01| Jun|
|123| 2012-01-01|2012-10-01| Jul|
|123| 2012-01-01|2012-10-01| Aug|
|123| 2012-01-01|2012-10-01| Sep|
|123| 2012-01-01|2012-10-01| Oct|
|234| 2012-01-01|2012-05-01| Jan|
|234| 2012-01-01|2012-05-01| Feb|
|234| 2012-01-01|2012-05-01| Mar|
|234| 2012-01-01|2012-05-01| Apr|
|234| 2012-01-01|2012-05-01| May|
|345| 2012-01-01|2012-11-01| Jan|
|345| 2012-01-01|2012-11-01| Feb|
|345| 2012-01-01|2012-11-01| Mar|
|345| 2012-01-01|2012-11-01| Apr|
|345| 2012-01-01|2012-11-01| May|
+---+-----------+----------+-----+