AlexBrunet
AlexBrunet

Reputation: 87

Spark Scala where date is greater than

I want to create a function to get the last 4 days on data including today. Here's my function, what am I missing? When I run a test I got an empty table.

df.where(trunc(col("date"),"day") >= date_add(current_date(),-4))

enter image description here

Upvotes: 0

Views: 1459

Answers (1)

mck
mck

Reputation: 42422

Try to use date_trunc instead. trunc only supports month and year. Also note that date_trunc accepts arguments in the reverse order of trunc.

df.where(date_trunc("day",col("date")) >= date_add(current_date(),-4))

Upvotes: 2

Related Questions