clickwerse
clickwerse

Reputation: 45

How to get date of first day three months ago from a date in sql?

for Example there is a date '2021-08-21', I need to convert it to '2021-05-01' I am confused with right functions to use as I want it to use it in Apache Spark SQL.

Upvotes: 0

Views: 1533

Answers (1)

werner
werner

Reputation: 14895

You can use add_month first and then use date_trunc to get the first day of the result of add_month.

select date_trunc('MONTH', add_months(date, -3))

Upvotes: 1

Related Questions