관리 메뉴

IT.FARMER

javascript 날짜 between 유사기능 (날짜와 날짜 사이) 본문

JavaScript/script

javascript 날짜 between 유사기능 (날짜와 날짜 사이)

아이티.파머 2010. 9. 24. 14:05
반응형

start_expirationDate 와 end_expirationDate 사이에 기준 날짜가 끼어 있으면 OOO기능을 수행한다.

 

function dateCheck(start_expirationDate, end_expirationDate ){
    var today = new Date();
    var criterionDate  =  new Array();
    
    var resultCalObj = calenderTemplate(today);
    
    criterionDate.push(today.getFullYear());
    criterionDate.push(resultCalObj.temp_geyMonth);    
    criterionDate.push(resultCalObj.temp_getDate);
    
    criterionDate = criterionDate.join("");
    start_expirationDate = "20100923";
    end_expirationDate   = "20100924";
    
    //1.공지 팝업 시작 날짜가 기준(오늘) 날짜보다 크거나 같으면,true 
    //2.공지 팝업 종료 날짜가 기준(오늘) 날짜보다 크거나 같으면, true  
    if(criterionDate <= start_expirationDate){
     if(criterionDate <= end_expirationDate){
      alert(criterionDate);    
     }
    }else if(criterionDate > start_expirationDate){
     if(criterionDate <= end_expirationDate){
      alert(criterionDate);
     }
    }
   }

   // @criterionDate : 기준날짜 , 
   //  #sample 형식 :201011
   //          결과 :20100101
   function calenderTemplate(criterionDate){
    var temp_geyMonth  = "";
    var temp_getDate   = "";
    
    if(criterionDate.getMonth()+1 < 10){
     temp_geyMonth = "0"+eval(criterionDate.getMonth()+1);
    }else{
     temp_geyMonth = criterionDate.getMonth()+1;
    }
    if(criterionDate.getDate() <10){
     temp_getDate = "0"+ criterionDate.getDate();
    }else{
     temp_getDate = criterionDate.getDate();
    }
    var resultObj = {
      "temp_geyMonth" : temp_geyMonth,
      "temp_getDate"  : temp_getDate
    }
    return resultObj;
   }


 

반응형