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

**URL:** <https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-util-date/56257>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [February 17, 2022, 2:57pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-util-date/56257 "2022-02-17T14:57:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diedric\_van\_Barnevel](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@Diedric\_van\_Barnevel](https://forum.inductiveautomation.com/u/Diedric_van_Barnevel)\
**Post date:** [February 17, 2022, 2:57pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-util-date/56257/1 "2022-02-17T14:57:07Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 17, 2022, 3:05pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-util-date/56257/2 "2022-02-17T15:05:52Z")

</div>

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

Add open and close parenthesis at the end.

---

<div class="post-metadata">

**Author:** ![Diedric\_van\_Barnevel](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@Diedric\_van\_Barnevel](https://forum.inductiveautomation.com/u/Diedric_van_Barnevel)\
**Post date:** [February 17, 2022, 3:09pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-into-type-class-java-util-date/56257/3 "2022-02-17T15:09:05Z")

</div>

Bit of a rookie mistake, thank you.
