I need to get the first date of month of any date using Spark SQL.
I have date column in my table
date_add(last_day(add_months(<date_column>, -1)),1)
In pyspark
(>= v1.5) you can use the trunc
function:
import pyspark.sql.functions as sf
df.withColumn('first_of_month', sf.trunc('date_col', 'month'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With