Arithmetic functions allow you to perform arithmetic operations on columns containing dates.
For example, you can calculate the difference between two dates, add days to a date, or subtract days from a date. Built-in date arithmetic functions include datediff , date_add , date_sub , add_months , last_day , next_day and months_between .
From the foregoing, we need
date_sub (timestamp startdate, int days), target: subtracts the specified number of days from the TIMESTAMP value. The first argument can be a string that is automatically cast to TIMESTAMP if it uses a recognized format, as described in the TIMESTAMP data type. Return Type: timestamp
and we have
current_timestamp () Purpose: alias for the now () function. Return Type: timestamp
You can choose
date_sub(CAST(current_timestamp() as DATE), 1)
See https://spark.apache.org/docs/1.6.2/api/java/org/apache/spark/sql/functions.html.
source share