1、日期加减
spark sql 日期加减,date_sub,date_add
val dateDF=spark.range(10) .withColumn("today",current_date()) .withColumn("now",current_timestamp()) dateDF.createOrReplaceTempView("dateTable") dateDF.printSchema() dateDF.select(date_sub(col("today"),5),date_add(col("today"),5)).show(1) spark.sql("select date_sub(today,5),date_add(today,5) from dateTable").show(1)
2、计算两个日期之间相差的天数 (datediff)
datediff(endDate,startDate)
datediff(LEAST('" + getDateNow() + "',end_date),f_due_date)
spark.sql("select datediff('2019-11-09','2019-11-08') ").show() // 1
spark.sql("select datediff('2019-11-09','2019-10-08') ").show() //32
https://www.cnblogs.com/feiyumo/p/8760846.html
sparksql 内置日期时间函数
http://bcxw.net/article/543.html
3、计算当前时间
spark.sql("SELECT current_timestamp()").show(false)//到年月日时分秒
spark.sql("SELECT now()").show(false)//同上
spark.sql("SELECT date_format(now(),'yyyy-MM-dd HH:mm:ss')").show(false)
spark.sql("SELECT current_date()").show(false)//到天