<a href="javascript:fn_GetDate('1');" class="btn_day">1일</a>

<a href="javascript:fn_GetDate('7');" class="btn_day">1주</a>

<a href="javascript:fn_GetDate('30');" class="btn_day">1달</a>



<div class="day_box" style="height:25px">    // 자바단에서 화면단으로 오늘날자 날자 넘겨줌.

<input id="fromDay" name="fromDay" type="text" value="${resultVo.fromDate}" class="btn_date" style="width: 100px; cursor:pointer" />

      <input id="toDay" name="toDay" type="text" value="${resultVo.toDate}" class="btn_date" style="width: 100px; cursor:pointer" />

</div>



<script type="text/javascript">

$(document).ready(function() {

$("#fromDay").datepicker();    // date_picker 오늘날짜

$("#toDay").datepicker();

if($("#fromDay").val() == ""){

$("#fromDay, #toDay").val($.datepicker.formatDate($.datepicker.ATOM, new Date()));

}

$("#dateSearch").click( function (){

fn_ChannelReportView();

});

//CP별 채널리스트 출력

fn_selectCompany($("#admin_information_id_temp").val());

$("#searchSelectChannel").val($("#channel_id").val());

});



//  날짜계산 JS

function fn_GetDate(num) {

var date = new Date();

var dayOfMonth = date.getDate();

var FMonth = date.getMonth();

var year = date.getFullYear();

var month = date.getMonth() + 1;

var day = date.getDate();

var fromYear = date.getFullYear();

var fromMonth = date.getMonth() + 1;

var fromDay = date.getDate();

if(num == "1") {

date.setDate(dayOfMonth);


} else if(num == "7"){

if(dayOfMonth <= "7") {

month = FMonth;

}

date.setDate(dayOfMonth - 7);

day = date.getDate();

} else if(num == "30") {

date.setMonth(FMonth, dayOfMonth);

month = date.getMonth();

}

var fromDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);

var toDay = fromYear + "-" + (fromMonth < 10 ? "0" + fromMonth : fromMonth) + "-" + (fromDay < 10 ? "0" + fromDay : fromDay);

$("#fromDay").val(fromDate);

$("#toDay").val(toDay);

}




==========================


통계 같은경우 하루전 데이터를 기준으로 삼을때.

소스 정리는 나중에........


/*  

  1일 ,1주, 한달 클릭시 오늘 -1일 기준으로 시작일과 마지막일을 보낸다.

1일인 경우 0일이 되므로 , 전달 마지막 일로 한다.

*/


function fn_GetDate(num) {    

var date = new Date();

var dayFlag = date.getDate()-1;  // 오늘날짜 구하기

if(dayFlag != 0){ // 1일이 아닐때...

var FMonth = date.getMonth();

var dayOfMonth = date.getDate();

// fromDate

var fromYear = date.getFullYear();

var fromMonth = date.getMonth() + 1;

var fromDay = date.getDate();

// toDate

var year = date.getFullYear();

var month = date.getMonth()+1;

var day = date.getDate();

if(num == "1") {

date.setDate(dayOfMonth);

} else if(num == "7"){

if(dayOfMonth <= "7") {

month = FMonth;

}

date.setDate(dayOfMonth - 7);

day = date.getDate();

} else if(num == "30") {

date.setMonth(FMonth, dayOfMonth);

month = date.getMonth();

}

//출력부

var fromDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);

var toDay = fromYear + "-" + (fromMonth < 10 ? "0" + fromMonth : fromMonth) + "-" + (fromDay < 10 ? "0" + fromDay : fromDay);

$("#fromDay").val(fromDate);

$("#toDay").val(toDay);

} else { //오늘 -1 일로 일이 0 일경우 date 전월 마직막날로 ( 년도입력, 월입력, 0)

var lastDay = ( new Date( date.getFullYear(), date.getMonth(), 0) ).getDate(); // 전달 마지막일 구함.

var FMonth = date.getMonth() ;

var dayOfMonth = lastDay;

// fromDate

var fromYear = date.getFullYear();

var fromMonth = FMonth;

var fromDay = lastDay;

// toDate

var year = date.getFullYear();

var month = FMonth;

var day = lastDay;

if(num == "1") {

date.setDate(dayOfMonth);

} else if(num == "7"){

if(dayOfMonth <= "7") {

month = FMonth;

}

date.setDate(dayOfMonth - 7);

day = date.getDate();

} else if(num == "30") {

date.setMonth(FMonth, dayOfMonth);

month = date.getMonth()-1;

}

//출력부

var fromDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);

var toDay = fromYear + "-" + (fromMonth < 10 ? "0" + fromMonth : fromMonth) + "-" + (fromDay < 10 ? "0" + fromDay : fromDay);

$("#fromDay").val(fromDate);

$("#toDay").val(toDay);

}


}








+ Recent posts