/**

 * 

 * @param interval : yyyy(년), m(월), d(일)

 * @param number : 증가 년, 월, 일

 * @param dateformat : 날짜 문자열

 * @returns {String} yyyymmdd 8자리로 리턴

 */

function DateAdd(interval, number, dateformat) {

dateformat = clear_DateSTRING(dateformat);

var int_millisecond = 1;

var int_second      = 1000 * int_millisecond;

var int_minute      = 60 * int_second;

var int_hour        = 60 * int_minute;

var int_day         = 24 * int_hour;

var YY_form = CInt(Left(dateformat, 4));

var MM_form = CInt(Mid(dateformat, 5, 2))-1;

var DD_form = CInt(Right(dateformat, 2));

var date = new Date(YY_form, MM_form, DD_form);

var date_milliseconds = date.valueOf();

var add_milliseconds  = 0;

var ret_date = null;

switch (interval) {

case "yyyy":

date.setFullYear(date.getFullYear()+number, date.getMonth(), date.getDate());

ret_date = date;

break;

case "m":

date.setFullYear(date.getFullYear(), date.getMonth()+number, date.getDate());

ret_date = date;

break;

case "d":

add_milliseconds  = number * int_day;

ret_date = new Date(date_milliseconds + add_milliseconds);

break;

}

var year  = ret_date.getFullYear();

var month = ret_date.getMonth() + 1;

if ( month < 10 ) {

month = "0" + month;

}

var day   = ret_date.getDate();

if ( day < 10 ) {

day = "0" + day;

}

return ( "" + year + month + day );

}


저작자 표시 비영리 변경 금지
신고
posted by 뚱2