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

Time:10-13

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.

CodePudding user response:

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))
  • Related