Dataframe- minus minutes from timestamp column

2019-09-06 14:13发布

问题:

Environment: Spark 1.6 ; Scala

Simple question, but I did not get accurate answer. I have a dataframe DF

id | cr_date
-----------------------
1| 2017-03-17 11:12:00
----------------------
2|2017-03-17 15:10:00

I need to minus 5 minutes from cr_date. I tried

val DF2= DF.select ($"cr_Date".cast("timestamp").minusMinutes(5)) // Did not work

Any suggestion? Thanks

回答1:

df.select(from_unixtime(unix_timestamp(col("cr_dt")).minus(5 * 60), "YYYY-MM-dd HH:mm:ss"))

There is no such minusMinutes method available in spark. The above code should return expected results.