Convert date to end of month in Spark

久未见 提交于 2019-12-05 16:59:30
Leonard Aukea

You may use the following (PySpark):

from pyspark.sql.functions import last_day

df.select('name', last_day(df.dates).alias('dates')).show()

To clarify, last_day(date) returns the last day of the month of which date belongs to.

I'm pretty sure there is a similar function in sparkR https://spark.apache.org/docs/1.6.2/api/R/last_day.html

For completeness, here is the SparkR code:

df <- withColumn(df, 'dates', last_day(df$dates))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!