Live Brilliant

해당 주(월)의 시작일과 마지막일자 구하는 방법 본문

개발은 핵찜이야/PHP

해당 주(월)의 시작일과 마지막일자 구하는 방법

주인정 2012. 4. 13. 19:04

//넘어오는 변수값이 없으면 오늘 기준으로 값 설정
if(!$thisY) $thisY = date("Y");
if(!$thisM) $thisM = date("m");
if(!$thisD) $thisD = date("d");
$thisW = date("w",mktime(12,12,12,$thisM,$thisD,$thisY)); // 0(일요일)에서 6(토요일)

// 해당 주차의 시작 날짜 (일요일)..timestamp
$thisStartW = mktime(0,0,0,$thisM,$thisD-$thisW,$thisY);
// 해당 주차의 마지막 날짜 (토요일)..timestamp
$thisEndW = mktime(23,59,59,$thisM,$thisD+(6-$thisW),$thisY);

// 해당 월의 시작 날짜 (1일).. timestamp
$thisStartM = mktime(0,0,0,$thisM,1,$thisY);
// 해당 월의 마지막 날짜 (마지막날)..timestamp
// date 옵션 `t`  주어진 월의 일수 ( 28~31)

$thisEndM = mktime(23,59,59,$thisM,date("t",$thisStartM),$thisY);


// 주간 만근에 대한 처리
$sql = "select * from event_attend where mnum='$mnum' and date > $thisStartW and date < $thisEndW";
$result = mysql_query($sql) or die($sql);
$thisWeekCount = mysql_num_rows($result); // 해당주간의 출석 카운터.. 0 이면 출석한번도 안 함 사람, 7이면 만근..

// 월간 만근에 대한 처리
$sqlM = "select * from event_attend where mnum='$mnum' and date > $thisStartM and date < $thisEndM";
$resultM = mysql_query($sqlM) or die($sqlM);
$thisMonthCount = mysql_num_rows($resultM); // 해당 월의 출석 카운터

 

date("w") : 0(일요일)에서 6(토요일)

'개발은 핵찜이야 > PHP' 카테고리의 다른 글

PHP OOP 프로그래밍  (0) 2012.07.02
hash md5 reverse  (0) 2012.05.18
페이지 로딩시간 표시  (0) 2012.04.13
ob_start() , ob_end_flush() 함수 사용  (0) 2012.04.13
암호화 소스( 숫자 암호화,숫자 복호화)  (0) 2012.04.13
Comments