군침이 싹 도는 코딩
MySQL 시간의 차이를 구하는 함수 (datediff,date_add,date_sub,interval) 본문
Database/MySQL
MySQL 시간의 차이를 구하는 함수 (datediff,date_add,date_sub,interval)
mugoori 2022. 12. 7. 16:44select datediff( now(),birthdt )
from people;

# 현재시간에서 입력된 시간값과의 차이를 구한다
select birthdt, date_add(birthdt, interval 1 day )
from people;

# date_add 와 interval을 사용해 시간차이를 구할수도 있다
뒤에는 년월일시간전부를 입력할수있다
select birthdt, birthdt - interval 9 day + interval 3 hour
from people;

# 연산기호로 사용도 가능하며 연속적으로 사용도 가능하다
'Database > MySQL' 카테고리의 다른 글
MySQL 조건문 처리하는 방법 (case,if) (0) | 2022.12.07 |
---|---|
MySQL 데이터를 가져오는 여러 방법 (!=,not like,between A and B,in,is null) (0) | 2022.12.07 |
MySQL 현재 시간을 가져오고 싶을때 함수 (now,curdate,curtime) (0) | 2022.12.07 |
MySQL 시간 데이터를 사람이 보기 편하게 바꾸기 (date_format) (0) | 2022.12.07 |
MySQL 날짜 정보 가져오기 (day,dayname,dayofweek,dayofmonth,dayofyear) (0) | 2022.12.07 |