Posted By

kouphax on 11/28/08


Tagged

groovy between dates months


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ginoplusio
sfhynx


Calculate Number of Months Between 2 Dates


 / Published in: Groovy
 

Calculates the number of Months between 2 given dates

  1. def monthsBetween(from, to){
  2.  
  3. def cfrom = new GregorianCalendar(time:from)
  4. def cto = new GregorianCalendar(time:to)
  5.  
  6. return ((cto.get(Calendar.YEAR) - cfrom.get(Calendar.YEAR))
  7. * cto.getMaximum(Calendar.MONTH))
  8. + (cto.get(Calendar.MONTH) - cfrom.get(Calendar.MONTH))
  9. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: murugadosssnipplr on September 17, 2009

i need to full execution code

You need to login to post a comment.