Home > Web Front-end > JS Tutorial > body text

JS sample code to compare 2 date intervals_javascript skills

WBOY
Release: 2016-05-16 16:52:25
Original
1177 people have browsed it
Copy code The code is as follows:














sourceFormat="yyyy-MM-dd" targetFormat="yyyy-MM-dd" readonly="true"/>







var startDate=document.forms[0]. startDate.value;

var endDate=document.forms[0].endDate.value;

if(DateDiff(endDate,startDate)>3){

alert ("The day range should not exceed three days");

return;

}

function DateDiff(endDate,startDate)

{

var arrDate,objDate1,objDate2,intDays;

arrDate=endDate.split("-");

objDate1=new Date(arrDate[1] '-' arrDate[2] '-' arrDate[0]);

arrDate=startDate.split("-");

objDate2=new Date(arrDate[1] '-' arrDate[2] '- ' arrDate[0]);

intDays=parseInt(Math.abs(objDate1-objDate2)/1000/60/60/24);

return intDays;

}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template