How to compare date in Groovy Script

I have to compare two dates in groovy script. Both date will read through getVariable function. I an not able to compare of not able to format it.

Need help

date1.compareTo(date2)