본문 바로가기
MySql

MySQL 날짜 SQL에 2 주 추가

by 베이스 공부 2020. 12. 17.
반응형

DB에 날짜를 입력해야하는데 그 날짜로부터 2 주 후에 종료 날짜를 설정하고 싶습니다.

어떻게 만들 수 있습니까?

내 선택에는 다음과 같은 것이 필요하다고 생각합니다.

insert into table values (current_Date, current_Date+2weeks) where....

그러나 나는 그것을하는 방법을 모른다.

 

해결 방법

 

mysql 용

INSERT INTO tbl(fromdate,todate) values (now(), DATE_ADD(now(),INTERVAL 2 WEEK))

SQL 서버용

 INSERT INTO tbl(fromdate,todate) values( current_timestamp, DATEADD(week,2,current_timestamp))

 

참조 페이지 https://stackoverflow.com/questions/19925400

 

 

반응형

댓글