How can I calculate the difference between the current date time vs. another date time using Groovy?

To calculate the difference between the current date time vs. another date time for any given row, you can use the Groovy sample script below.

Here's an example that uses the creation date for opportunities:

def dt2 = now();

def dt1 = CreationDate;

long diffInMills = dt2.getTime() - dt1.getTime();



println("Diff between Creation Date:" + CreationDate + " and today: " + dt2 );

println("The difference in milliseconds is:" + diffInMills          );

println("The difference in seconds:"     + diffInMills / 1000      );

println("The difference in minutes:"     + diffInMills / (1000*60)    );

println("The difference in hours:"      + diffInMills / (1000*60*60)  );

println("The difference in days:"      + diffInMills / (1000*60*60*24) );