I want to get the number of months between two dates, I'm reading the start date and end date from csv file.
id startDate endDate
100 5/1/2016 5/1/2017
200 5/2/2016 5/1/2017
300 5/2/2016 5/1/2017
My output should look like:
id startDate endDate res
100 5/1/2016 5/1/2017 12
200 5/2/2016 5/1/2017 11
300 5/3/2016 5/1/2017 10
Please let me know what is the wrong in my code,
val data = spark.read.option("header", "true").csv("sample.csv");
val result = data.withColumn("res", withColumn("Months", ChronoUnit.MONTHS.between(startDate ,endDate)).show()