Cannot coerce value <> into type: class java.util.Date

I have a function to call midnight the day before the current day :

def getYesterdayStartOfDay(datetime):
year=system.date.getYear(datetime)
month=system.date.getMonth(datetime)
today=system.date.getDayOfMonth(datetime)
yesterday=today-1
return toDate(system.date.setTime(system.date.getDate(year,month,yesterday),0,0,0))

And call the function as follows :

startDate = getYesterdayStartOfDay

The error I keep getting is :

Caused by: java.lang.ClassCastException: Cannot coerce value ‘<function getYesterdayStartOfDay at 0x6>’ into type: class java.util.Date

I have tried system.date.parse(getYesterdayStartOfDay) which results in “unparseable date”

You aren’t actually calling that function, you are assigning it to a variable.

Add open and close parenthesis at the end.

1 Like

Bit of a rookie mistake, thank you.