<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script> function f_leapyear(yy) //윤달 계산 { if (yy%4==0 && yy%100!=0 || yy%400==0) return 1; else return 0; } // Check how many days there are on the inputted year and month // 년과 달을 입력하면, 한달에 몇일이 있는지 확인하는 함수입니다. function f_dayofmonth(yy,mm) { switch (mm){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: return 28 + f_leapyear(yy); } } function day_cal(yy, mm, dd){ //해당년도만의 일수 계산 var tot = 0; for(var i=1;i<mm;i++){ tot += f_dayofmonth(yy,i); } return tot+dd; } function getDiffDay(val1, val2){ //날짜 일수 계산 var sdate_year = Number(val1.substr(0,4)); var sdate_month = Number(val1.substr(4,2)); var sdate_day = Number(val1.substr(6,2)); var edate_year = Number(val2.substr(0,4)); var edate_month = Number(val2.substr(4,2)); var edate_day = Number(val2.substr(6,2)); var year_result = edate_year-sdate_year; var tot = 0; for(i=sdate_year;i<edate_year+1;i++){ tot += f_leapyear(i); } tot += year_result*365; //년도 차이 일수 계산 tot += -day_cal(sdate_year, sdate_month, sdate_day)+1; //시작 날짜 일수 계산 tot += day_cal(edate_year, edate_month, edate_day); //종료 날짜 일수 계산 return tot; } </script> </HEAD> <BODY> <script> alert(getDiffDay('20090101', '20090228')); </script> </BODY> </HTML>