본문 바로가기
개발자공간/SCRIPT

jquery & javascript 날짜비교 방법

by 냉국이 2020. 12. 10.
728x90
var startDate = $( "input[name='startDate']" ).val();

var startDateArr = startDate.split('-');
var endDate = $( "input[name='endDate']" ).val();
var endDateArr = endDate.split('-');

var startDateCompare = new Date(startDateArr[0], parseInt(startDateArr[1])-1, startDateArr[2]);
var endDateCompare = new Date(endDateArr[0], parseInt(endDateArr[1])-1, endDateArr[2]);


if(startDateCompare.getTime() > endDateCompare.getTime()) {
	alert("시작날짜와 종료날짜를 확인해 주세요.");
	return false;
}

 

300x250

댓글