Assuming your format is yyyy-MM-dd where MM starts with 0,The code to find the days difference is as follows
<script language=javaScript>
function fun1()
{
var sdt = "2011-03-04";
var edt = 2011-04-05;
sYear=sdt.substring(0,4);
sMonth=parseInt(sdt.substring(5,7))-1;
sDate=sdt.substring(8,10);
alert(sYear+"::"+sMonth+"::"+sDate)
eYear=edt.substring(0,4);
eMonth=parseInt(edt.substring(5,7))-1;
eDate=edt.substring(8,10);
var dt1=new Date()
dt1.setFullYear(sYear,sMonth,sDate); //yyyy,mm,date
var dt2=new Date()
dt2.setFullYear(eYear,eMonth,eDate);
var milliSecDiff=dt2.getTime() - dt1.getTime();
var daysDiff=milliSecDiff/(1000*60*60*24);
alert(daysDiff);
}
</script>
<script language=javaScript>
function fun1()
{
var sdt = "2011-03-04";
var edt = 2011-04-05;
sYear=sdt.substring(0,4);
sMonth=parseInt(sdt.substring(5,7))-1;
sDate=sdt.substring(8,10);
alert(sYear+"::"+sMonth+"::"+sDate)
eYear=edt.substring(0,4);
eMonth=parseInt(edt.substring(5,7))-1;
eDate=edt.substring(8,10);
var dt1=new Date()
dt1.setFullYear(sYear,sMonth,sDate); //yyyy,mm,date
var dt2=new Date()
dt2.setFullYear(eYear,eMonth,eDate);
var milliSecDiff=dt2.getTime() - dt1.getTime();
var daysDiff=milliSecDiff/(1000*60*60*24);
alert(daysDiff);
}
</script>
No comments:
Post a Comment