Search code examples
sqlapache-spark-sqlazure-databricks

How to migrate SQL Date ADD script into Spark supported SQL format


I have to implement delete operation for my incremental load purpose, so that I have to do the below statement of the query to migrate spark SQL supported. SQL based queries

DATEADD(DAY, 1, EOMONTH(CURRENT_TIMESTAMP, -2))

expecting how to use spark supported without change the output of the above script.


Solution

  • Use the below databricks SQL query to achieve your requirement. Here it uses, combination of add_months() and last_day() functions where last_day() function give the last day of the month and next one adds or removes required months.

    select date_add(add_months(last_day(current_date()),-2),1) as mydate;
    

    Result:

    enter image description here