사이트에서 월별, 주별 이벤트 참여자의 순위를 랭크하는 작업이 있어서 기존에 유통되는 자바스크립트 함수를

asp버전으로 급히 변환(converting)한 것입니다. 함수는 총3개로 구성되어 있으며 하단의 weekCount 함수

에 년,월의 인자만 넘겨주면 이번달에 속한주가 몇주까지 있나를 리턴(return) 해 줍니다. 


처음에 올린 datepart 함수를 이용하면 해당월에 속한 주수를 구할수 있을것 같으나 쉽지는 않습니다. 처음 예제 그대로

따라하시면 해당월에 속한주가 6주까지도 있다는 괴상한 값을 받을 것입니다.


-> wcountMonth = datepart("ww", today) - datepart("ww", firstdate) + 1  이부분에 dateserial 함수를 이용했을경우 5~6주가 넘어옴


 

------------------------------------------------함수는 여기부터 ---------------------------------------------------------


<%
 function isLeapYear (Year)
 
 dim bisReturn


 if (( Year mod 4 = 0 ) and (( Year mod 100 ) <> 0 ) or (( Year mod 400 ) = 0 )) then
   bisReturn = true
 else
   bisReturn = false
 end if

   isLeapYear = bisReturn
  
 end function


 function getDayInMonth(month,year)
 
 dim days
 
 if( month = 1 or month = 3 or month = 5 or month = 7 or month = 8 or month = 10 or month = 12 ) then
   days = 31
 else
  if ( month = 4 or month = 6 or month = 9 or month = 11 ) then
   days = 30
  else
   if  IsLeapYear(Year)  then
    days = 29
   else
    days = 28
   end if
  end if
 end if


 getDayInMonth = days

end function

function weekCount(thisYear, thisMonth)

  dim i, j
  i = 0
  j = 0

  for i = 1 to getDayInMonth(cint(thisMonth), cint(thisYear))
  
   
 
 tempDay = thisYear & "-" & thisMonth & "-"  & cstr(i)

    '월요일이 나올때 마다 j값을 증가시킨다  참고: 1은 일요일, 2는 월요일, 3은 화요일, 4는 수요일,
 '5는 목요일, 6은 금요일, 7은 일요일
    if  weekday(tempDay) = 2  then
      j = j+1
 end if

  next

  if(( thisMonth = 1 ) or ( thisMonth = 10 )) then
    j = 5
  end if


  weekCount = j

end function
%>
<% '//---- 해당년과 해당월을 weekCount 함수에 넘기면 해당월에 몇주가 있나를 리턴해줍니다.  ----//
<% response.Write weekCount( "2006", "9" ) %>


-----------------------------------------------   함수 끝  -------------------------------------------------------------


기회가 되면 컨버팅전의 자바스크립트 함수도 올리도록 하겠습니다.

2008/02/21 15:24 2008/02/21 15:24

Trackback Address :: https://youngsam.net/trackback/155