Monday, June 25, 2012

Java script code to find the difference between 2 dates in terms of months

Its easy to find the month difference in Java since java supports calendar objects.
But java script supports Date objects but not calendar objects.
Here is a code for finding the month difference in javascript.

function getMonthsDifference(firstDate,lastDate)
{
 var date1DtParse = Date.parse(lastDate);
 var date2DtParse = Date.parse(firstDate);
 var date1 = new Date(date1DtParse);         
 var date2 = new Date(date2DtParse);

 var diffYears = date2.getFullYear()-date1.getFullYear();
 var diffMonths = date2.getMonth()-date1.getMonth();
 var diffDays = date2.getDate()-date1.getDate(); 
 var months = (diffYears*12 + diffMonths);
 if(diffDays>0)
 {     months += '.'+diffDays; }
 else if(diffDays<0)
 {     months--;    
 months += '.'+(new Date(date2.getFullYear(),date2.getMonth(),0).getDate()+diffDays);
 }
 return months;
}

Resolve "Target runtime Apache Tomcat v6.0 is not defined." error

Go to window ->preferences ->Server->Runtime environments . add server Apache Tomcat v6.0 Mention the directory where apache-toma...