[ https://issues.apache.org/jira/browse/SPARK-38341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17498712#comment-17498712 ]
Yang Jie edited comment on SPARK-38341 at 2/28/22, 5:48 AM: ------------------------------------------------------------ I don't think it's a Spark 3.2.1 bug. last_day('2020-06-30') is '2020-06-30', and the result of ADD_MONTHS('2020-06-30', -1) is same as `java.time.LocalDate.of(2020, 6, 30).plusMonths(-1)` and `new org.joda.time.LocalDate(2020, 6, 30).plusMonths(-1)`. You can use `last_day(ADD_MONTHS('2020-06-30', -1))` instead to get the results you want. was (Author: luciferyang): I don't think it's a Spark 3.2.1 bug. last_day('2020-06-30') is '2020-06-30', and the result of ADD_MONTHS('2020-06-30', -1) is same as that of `java.time.LocalDate.of(2020, 6, 30).plusMonths(-1)` and `new org.joda.time.LocalDate(2020, 6, 30).plusMonths(-1)`. You can use `last_day(ADD_MONTHS('2020-06-30', -1))` instead to get the results you want. > Spark sql: 3.2.1 - Function of add_ Months returns an incorrect date > -------------------------------------------------------------------- > > Key: SPARK-38341 > URL: https://issues.apache.org/jira/browse/SPARK-38341 > Project: Spark > Issue Type: Bug > Components: SQL > Affects Versions: 3.2.1 > Reporter: davon.cao > Priority: Major > > Step to reproduce: > Version of spark sql: 3.2.1(latest version in maven repository) > Run sql: > spark.sql("""SELECT ADD_MONTHS(last_day('2020-06-30'), -1)""").toPandas() > expect: 2020-05-31 > actual: 2020-05-30 (x) > > Version of spark sql: 2.4.3 > spark.sql("""SELECT ADD_MONTHS(last_day('2020-06-30'), -1)""").toPandas() > expect: 2020-05-31 > actual: 2020-05-31 (/) > -- This message was sent by Atlassian Jira (v8.20.1#820001) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org