Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading