JavaScript - 날짜 검색시 유용한 팁
시작일 : Start_Date, 2009-01-01
종료일 : End_Date, 2009-01-31
function SearchCheck(){
if(Document.SearchForm.Start_Date.value.length !=10){
alert("10자리의 날짜를 입력하셔야 합니다.");
Document.SearchForm.Start_Date.focus();
return ;
}
if(Document.SearchForm.End_Date.value.length !=10){
alert("10자리의 날짜를 입력하셔야 합니다.");
Document.SearchForm.End_Date.focus();
return ;
}
var s_str = Document.SearchForm.Star_Date.value;
var e_str = Document.SearchForm.End_Date.value;
var s_date = new Date( s_str.substring(0,4) , s_str.substring(5,7) , s_str.substring(8,10) );
var e_date = new Date( e_str.substring(0,4) , e_str.substring(5,7) , e_str.substring(8,10) );
// - 를 빼준다
var diff_date = e_date.getTime() - s_date.getTime();
// 차감일자
count = Math.floor( diff_date / (24*60*60*1000) );
// 차감숫자
if (count < 0 ){
alert("검색 시작일이 종료일보다 큽니다.\n확인해주시기 바랍니다.");
return;
}
if (count > 60){
alert("검색 속도로 인하여 60일 이상은 검색이 불가능합니다.");
return;
}
Document.SearchForm.submit();
}