Home > Enterprise >  How to create variable with the first day of current month in Databricks Spark Scala?
How to create variable with the first day of current month in Databricks Spark Scala?

Time:05-03

Using Spark Scala on Databricks, I am trying to create a variable that contains the first day of the current month.

In the first step, I just get the current date, and it works fine:

val current_date = LocalDate.now()

That gives me the correct output, such as:

current_date: java.time.LocalDate = 2022-05-02

My problem is when I try to get the first day of the current month. I have tried to use enter image description here

CodePudding user response:

I just had to use the method withDayOfMonth(1). The 1 inside the brackets indicates that it must return the first day of month.

The following code works:

val current_month = LocalDate.now().withDayOfMonth(1)

  • Related