Bootstrap Datepicker 달력에서 예약한 날짜를 Disabled 처리를 하기 위해 시작일과 종료일 사이의 날짜를 구하는 함수
function getDateRange(startDate, endDate, listDate)
{
var dateMove = new Date(startDate);
var strDate = startDate;
if (startDate == endDate)
{
var strDate = dateMove.toISOString().slice(0,10);
listDate.push(strDate);
}
else
{
while (strDate < endDate)
{
var strDate = dateMove.toISOString().slice(0, 10);
listDate.push(strDate);
dateMove.setDate(dateMove.getDate() + 1);
}
}
return listDate;
};
사용법
var listDate = [];
getDateRange('2017-02-01', '2017-02-05', listDate);
getDateRange('2017-02-07', '2017-02-07', listDate);
getDateRange('2017-02-09', '2017-02-12', listDate);
console.log(listDate);
결과
["2017-02-01", "2017-02-02", "2017-02-03", "2017-02-04", "2017-02-05", "2017-02-07", "2017-02-09", "2017-02-10", "2017-02-11", "2017-02-12"]
'프로그래밍 > Javascript' 카테고리의 다른 글
Polyfill (0) | 2023.03.08 |
---|---|
History back 시 무한 로딩 애니메이션 발생 (0) | 2023.02.15 |