저번주 금요일 쿼리
select DATE_FORMAT(NOW() - INTERVAL WEEKDAY(NOW()) + 3 DAY,'%Y%m%d') CNS_DATE
월요일을 구한다음 3일을 빼주면 저번주 금요일
참고로 2주전 금요일 쿼리
SELECT WEEKDAY('20160905')
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160905',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160905')+3) DAY)
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160906',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160906')+3) DAY)
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160907',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160907')+3) DAY)
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160908',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160908')+3) DAY)
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160909',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160909')+3) DAY)
;
=====================================================
결과
=====================================================
select DATE_FORMAT(NOW() - INTERVAL WEEKDAY(NOW()) + 3 DAY,'%Y%m%d') CNS_DATE
월요일을 구한다음 3일을 빼주면 저번주 금요일
참고로 2주전 금요일 쿼리
SELECT WEEKDAY('20160905')
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160905',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160905')+3) DAY)
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160906',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160906')+3) DAY)
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160907',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160907')+3) DAY)
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160908',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160908')+3) DAY)
UNION ALL
SELECT DATE_ADD(DATE_FORMAT(DATE_ADD('20160909',INTERVAL - 1 WEEK) ,'%Y%m%d'), INTERVAL - (weekday('20160909')+3) DAY)
;
=====================================================
결과
=====================================================
0 |
2016-08-26 |
2016-08-26 |
2016-08-26 |
2016-08-26 |
2016-08-26 |
댓글
댓글 쓰기