Spark SQL日期相距天數,月數

weixin_33912445發表於2018-06-03
dateDF.withColumn("week_ago",date_sub(col("today"),7))
.select(datediff(col("week_ago"),col("today"))).show(1)
dateDF.select(to_date(lit("2016-01-01")).as("start"),
to_date(lit("2017-05-22")).as("end"))
.select(months_between(col("start"),col("end"))).show(1)
spark.sql("select to_date('2016-01-01'),months_between('2016-01-01','2017-01-01'),
datediff('2016-01-01','2017-01-01') from dateTable").show(1)

相關文章