특정일의 주차, 요일 / 해당주의 시작일, 종료일 > 기술자료 | 해피정닷컴

특정일의 주차, 요일 / 해당주의 시작일, 종료일 > 기술자료

본문 바로가기

사이트 내 전체검색

특정일의 주차, 요일 / 해당주의 시작일, 종료일 > 기술자료

PHP 특정일의 주차, 요일 / 해당주의 시작일, 종료일

페이지 정보


본문

주의 기간은  일요일~토요일 입니다
요일계산 : 일 = 0, 월 = 1, 화 = 2, 수 = 3, 목 = 4, 금 = 5, 토 = 6 입니다.

테스트 : https://www.happyjung.com/demo/php/todayOfTheWeek.php

<?php
echo " 2021-01-01 = 2020년도 53주 금요일(5) 2020-12-27~2021-01-02 <br>";
echo " 2021-01-02 = 2020년도 53주 토요일(6) 2020-12-27~2021-01-02 <br>";
echo " 2021-01-03 = 2020년도 53주 일요일(0) 2021-01-03~2021-01-09 <br>";
echo " 2021-01-04 = 2021년도 01주 월요일(1) 2021-01-03~2021-01-09 <br>";
echo "<br>";

//$today_year  = date('Y');
//$today_month = date('m');
//$today_day   = date('d');

$today_year  = '2021';
$today_month = '01';
$today_day   = '03';

// 오늘날짜
$today_date = $today_year ."-". $today_month ."-". $today_day;
//today_date = 20210103

// 해당요일
$todayOfTheWeek1 = date('w',mktime(0,0,0,$today_month,$today_day,$today_year));
//todayOfTheWeek1 = 0
$todayOfTheWeek2 = date('w',strtotime($today_year.$today_month.$today_day));
//todayOfTheWeek2 = 0

// 요일 한글로 변환
if ($todayOfTheWeek1=="0") { $todayOfTheWeek_kor = "일"; $todayOfTheWeek_eng = "SUN"; }
elseif ($todayOfTheWeek1=="1") { $todayOfTheWeek_kor = "월"; $todayOfTheWeek_eng = "MON"; }
elseif ($todayOfTheWeek1=="2") { $todayOfTheWeek_kor = "화"; $todayOfTheWeek_eng = "TUE"; }
elseif ($todayOfTheWeek1=="3") { $todayOfTheWeek_kor = "수"; $todayOfTheWeek_eng = "WED"; }
elseif ($todayOfTheWeek1=="4") { $todayOfTheWeek_kor = "목"; $todayOfTheWeek_eng = "THU"; }
elseif ($todayOfTheWeek1=="5") { $todayOfTheWeek_kor = "금"; $todayOfTheWeek_eng = "FRI"; }
elseif ($todayOfTheWeek1=="6") { $todayOfTheWeek_kor = "토"; $todayOfTheWeek_eng = "SAT";}

// 주차구하기
$today_week1 = date('W',mktime(0,0,0,$today_month,$today_day,$today_year));
//today_week1 = 53
$today_week2 = date('W',strtotime($today_year.$today_month.$today_day));
//today_week2 = 53

// 해당주차의 시작 날짜
$today_week_sday1  = mktime(0,0,0,$today_month,$today_day-$todayOfTheWeek1,$today_year);
//today_week_sday1 = 1609599600
$today_week_sday2 = date("Y-m-d H:i:s",$today_week_sday1);
//today_week_sday2 = 2021-01-03 00:00:00

// 해당주차의 종료 날짜
$today_week_eday1 = mktime(23,59,59,$today_month,$today_day+(6-$todayOfTheWeek1),$today_year);
//today_week_eday1 = 1610204399
$today_week_eday2 = date("Y-m-d H:i:s",$today_week_eday1);
//today_week_eday2 = 2021-01-09 23:59:59

// 해당달의 시작 날짜
$today_week_month_sday1 = mktime(23,59,59,$today_month,1,$today_year);
//today_week_month_sday = 1609513199
$today_week_month_sday2 = date("Y-m-d H:i:s",$today_week_month_sday1);
//today_week_month_sday2 = 2021-01-01 23:59:59

// 해당월의 마지막 날짜
$today_week_month_eday1 = mktime(23,59,59,$today_month,date("t",$today_week_month_sday1),$today_year);
//today_week_month_eday1 = 1612105199
$today_week_month_eday2 = date("Y-m-d H:i:s",$today_week_month_eday1);
//today_week_month_eday2 = 2021-01-31 23:59:59

// 년도==12 & 주차=='01' 이면 디비저장년도=년도+1
if($today_month==12 & $today_week1=='01') { $today_year_db = $today_year+1; } // 년도 + 1
elseif($today_month==01 & $today_week1>'01') { $today_year_db = $today_year-1; } // 년도 - 1
else { $today_year_db = $today_year; }

if ($todayOfTheWeek1=="0") { // 일요일일때는 주차 - 1
    // 디비저장 해당주차의 시작 날짜 (월요일)
    $today_week_sday_db = date("Y-m-d H:i:s",strtotime("-6 day", $today_week_sday1));    //$today_week_sday_db = 2020-12-28 00:00:00
    //echo "today_week_sday_db = ".$today_week_sday_db."<br>";

    // 디비저장 해당주차의 마지막 날짜 (일요일)
    $today_week_eday_db = date("Y-m-d H:i:s",strtotime("-6 day", $today_week_eday1));    //$today_week_eday_db = 2021-01-03 23:59:59
    //echo "today_week_eday_db = ".$today_week_eday_db."<br>";
} else {
    // 디비저장 해당주차의 시작 날짜 (월요일)
    $today_week_sday_db = date("Y-m-d H:i:s",strtotime("1 day", $today_week_sday1));    //$today_week_sday_db = 2020-12-28 00:00:00
    //echo "today_week_sday_db = ".$today_week_sday_db."<br>";

    // 디비저장 해당주차의 마지막 날짜 (일요일)
    $today_week_eday_db = date("Y-m-d H:i:s",strtotime("1 day", $today_week_eday1));    //$today_week_eday_db = 2021-01-03 23:59:59
    //echo "today_week_eday_db = ".$today_week_eday_db."<br>";
}

echo "오늘날짜 = ". $today_date ."<br>";
echo "<br>";

echo "해당요일<br>";
echo "todayOfTheWeek1 = ". $todayOfTheWeek1 ."<br>";
echo "todayOfTheWeek2 = ". $todayOfTheWeek2 ."<br>";
echo "<br>";

echo "주차구하기<br>";
echo "today_week1 = ". $today_week1 ."<br>";
echo "today_week2 = ". $today_week2 ."<br>";
echo "<br>";

echo "해당주차의 시작 날짜<br>";
echo "today_week_sday1 = ". $today_week_sday1 ."<br>";
echo "today_week_sday2 = ". $today_week_sday2 ."<br>";
echo "<br>";

echo "해당주차의 마지막 날짜<br>";
echo "today_week_eday1 = ". $today_week_eday1 ."<br>";
echo "today_week_eday2 = ". $today_week_eday2 ."<br>";
echo "<br>";

echo "해당월의 시작 날짜<br>";
echo "today_week_month_sday1 = ". $today_week_month_sday1 ."<br>";
echo "today_week_month_sday2 = ". $today_week_month_sday2 ."<br>";
echo "<br>";

echo "해당월의 마지막 날짜<br>";
echo "today_week_month_eday1 = ". $today_week_month_eday1 ."<br>";
echo "today_week_month_eday2 = ". $today_week_month_eday2 ."<br>";
echo "<br>";

echo "디비저장<br>";
echo "년도 = ". $today_year_db ."<br>";
echo "주차 = ". $today_week1 ."<br>";
echo "날짜 = ". $today_year . $today_month . $today_day ."<br>";
echo "요일 = ". $todayOfTheWeek1 ."<br>";
echo "요일(한글) = ". $todayOfTheWeek_kor ."<br>";
echo "주시작(월) = ". $today_week_sday_db ."<br>";
echo "주종료(일) = ". $today_week_eday_db ."<br>";
?>


결과값
2021-01-01 = 2020년도 53주 금요일(5) 2020-12-27~2021-01-02
2021-01-02 = 2020년도 53주 토요일(6) 2020-12-27~2021-01-02
2021-01-03 = 2020년도 53주 일요일(0) 2021-01-03~2021-01-09
2021-01-04 = 2021년도 01주 월요일(1) 2021-01-03~2021-01-09

오늘날짜 = 2021-01-03

해당요일
todayOfTheWeek1 = 0
todayOfTheWeek2 = 0

주차구하기
today_week1 = 53
today_week2 = 53

해당주차의 시작 날짜
today_week_sday1 = 1609599600
today_week_sday2 = 2021-01-03 00:00:00

해당주차의 마지막 날짜
today_week_eday1 = 1610204399
today_week_eday2 = 2021-01-09 23:59:59

해당월의 시작 날짜
today_week_month_sday1 = 1609513199
today_week_month_sday2 = 2021-01-01 23:59:59

해당월의 마지막 날짜
today_week_month_eday1 = 1612105199
today_week_month_eday2 = 2021-01-31 23:59:59

디비저장
년도 = 2020
주차 = 53
날짜 = 20210103
요일 = 0
요일(한글) = 일
주시작(월) = 2020-12-28 00:00:00
주종료(일) = 2021-01-03 23:59:59


참고자료
https://www.funyphp.com/archive/php/15

댓글목록

등록된 댓글이 없습니다.


Total 195건 1 페이지
  • RSS
기술자료 목록
195
PHP   1520  2024-02-06 16:42  
194
PHP   1377  2024-01-26 11:04 ~ 2024-01-26 11:13  
193
PHP   3002  2023-11-20 10:56 ~ 2023-11-20 11:14  
192
PHP   4047  2023-04-14 18:22 ~ 2023-04-14 18:40  
191
PHP   3828  2022-11-16 18:17  
190
PHP   4354  2022-11-15 11:55 ~ 2022-11-18 17:26  
189
PHP   4372  2022-10-13 20:59 ~ 2022-10-14 09:44  
188
PHP   3594  2022-10-06 14:29  
187
PHP   3097  2022-10-06 12:20 ~ 2022-10-06 12:29  
186
PHP   4213  2022-05-20 12:09 ~ 2024-03-21 15:12  
185
PHP   7143  2022-02-27 03:45 ~ 2022-03-05 01:33  
184
PHP   5923  2021-12-20 20:32 ~ 2021-12-22 18:59  
183
PHP   7007  2021-11-09 17:52 ~ 2021-11-09 17:57  
182
PHP   6856  2021-06-30 10:40  
181
PHP   8187  2021-03-04 19:10 ~ 2021-06-22 00:03  
180
PHP   6930  2021-03-03 16:20 ~ 2021-03-03 16:21  
열람
PHP   11655  2021-01-20 12:07 ~ 2021-01-27 13:35  
178
PHP   7283  2020-11-08 13:01 ~ 2020-11-08 13:03  
177
PHP   8366  2020-11-06 20:08  
176
PHP   9042  2020-08-06 11:54 ~ 2022-12-14 13:44  

검색

해피정닷컴 정보

회사소개 회사연혁 협력사 오시는길 서비스 이용약관 개인정보 처리방침

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 1동 222호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 제2024-대전대덕-0405호 [사업자등록확인]  
Copyright 2001~2024 해피정닷컴. All Rights Reserved.