import org.apache.spark.sql.expressions.Window
val win =Window.orderBy("date_differnece")
val df= Seq(("FT1" ,"17-06-2019"), ("FT2" ,"19-06-2019"), ("FT3" ,"23-06-2019"),( "FT4", "25-06-2019"),("FT5", "27-06-2019")).toDF("flight", "dt")
val df1= df.withColumn("date_differnece", abs(datediff(current_date,to_date($"dt", "dd-MM-yyyy"))))
df1.select($"*", min($"date_differnece").over(win).as("nearest_flight")).where($"nearest_flight"===$"date_differnece").select($"dt")
+----------+
| dt|
+----------+
|17-06-2019|
+----------+