채택완료

다음주 월요일 일요일 을 못구하겠어요..ㅠㅠ

2017-06-01 (목) 10:48:13 9,624
Copy
$this_week_chk = date('w')-1; // 오늘$this_week_start = date("Y-m-d",strtotime("-".$this_week_chk." days")); // 이번주 월$this_week_end = date("Y-m-d",strtotime("+".$this_week_chk." days")); // 이번주 일 $next_week_chk = ??????????$next_week_start = date("Y-m-d",strtotime("-".$next_week_chk." days")); // 다음주 월$next_week_end = date("Y-m-d",strtotime("+".$next_week_chk." days")); // 다음주 일

이번주월요일, 이번주일요일은 구햇는데

다음주 월요일과 일요일은 어떻게 구할수있나요?ㅠㅠ

답변 3개 / 댓글 1개

채택된 답변
+20 포인트

$this_week_chk = date('w'); //요일을 숫자로 표시 일:0, 월:1, 화:2, 수:3, 목:4, 금:5, 토:6

$this_week_start = date("Y-m-d",strtotime("-".($this_week_chk - 1)." days")); // 이번주 월

$this_week_end = date("Y-m-d",strtotime("+".(7 -$this_week_chk)." days")); // 이번주 일

$next_week_start = date('Y-m-d',strtotime($this_week_start.' +7 day')); // 다음주 월

$next_week_end = date('Y-m-d',strtotime($next_week_start.' +6 day')); // 다음주 일

echo "다음주월:".$next_week_start."<br>";

echo "다음주일:".$next_week_end."<br>";

2017-06-01 (목) 11:15:16

그럼 이렇게 하면 어떨지요?

Copy
$gendate = new DateTime();$next_week_start = $gendate->setISODate(date("Y"),date("W")+1,1)->format('Y-m-d');$next_week_end = $gendate->setISODate(date("Y"),date("W")+2,0)->format('Y-m-d');

출처: https://stackoverflow.com/questions/20780834/how-to-get-date-from-week-number-day-number-and-year

2017-06-01 (목) 10:59:41
Copy
$next_week_start = date("Y-m-d",strtotime("next week monday")); // 다음주 월$next_week_end = date("Y-m-d",strtotime("next week sunday")); // 다음주 일

이렇게 해보시면 어떨까요?

답변에 대한 댓글 1개

2017-06-01 (목) 11:02:49
말씀해주신대로하니
다음주월요일에 2017-06-12(월)
다음주일요일에 2017-06-11(일)
이렇게 출력됩니다.ㅠㅠ

답변을 작성하려면 로그인이 필요합니다.