0

Ok, so I'm trying to "translate" some stuff into pyspark. The statement that I have is the following:

CONVERT(VARCHAR(6), DATEADD(MONTH, -1, DATEADD(MONTH, -1, GETDATE())),112) AS CURRENT_DATE

I've been searching and reading the documentation, but no clue how to do this. I'm new in both SQL and pyspark.

I tried to search a form of doing the same thing I did in SQL.

I want my CURRENT_DATE to be at the form of yyyymm, to do it so, I converted the date in varchar(6), the 112 correspond to yyyymmdd so it's a varchar(8), using varchar(6) will cut off the days. All the DATEADD works in pyspark and it's simply a form of getting the date I need.

The problem is I don't know how to write say yyyy-mm-dd (pyspark format I guess) as yyyymm.

  • So what research have you done? If I Google "pyspark date format" the first result points to the documentation and the `date_format()` function – Stu Jun 07 '23 at 22:21
  • @Stu, but the date_format is date_format(date, format) and in all formats of https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html here it doesn't have the one that I need – Isabela Branco Jun 07 '23 at 22:40
  • I don't use pyspark but what does this do for you? `date_format(current_timestamp(),"yyyyMM")` – Stu Jun 07 '23 at 22:44
  • @Stu, my error was just using yyyymm without the question mark and also not yyyyMM. Thank you a lot. – Isabela Branco Jun 07 '23 at 23:17

0 Answers0