728x90
테이블을 만들때 Datatype을 설정해줍니다.
DATE는 날짜만 출력하고 TIME은 시간만 출력, DATETIME은 두개 전부 출력합니다.
use YHDB;
insert into people2 (name,birthdate,birthtime,birthdt)
values ('Mike','1990-11-11','10:07:35','1990-11-11 10:07:35'),
('Larry','1972-12-25','04:10:42','1972-12-25 04:10:42');
select *
from people2;
-- 날짜 정보만 가져오기
select name,day(birthdate)
from people2;
select name,dayname(birthdate) -- 해당 날짜의 요일 출력
from people2;
select name,dayofweek(birthdate) -- 해당 날짜의 요일을 숫자로 출력
from people2;
select name,dayofyear(birthdate) -- 해당 날짜가 1년중 며칠이 지났는지 확인
from people2;
select name, month(birthdate) -- 해당 월
from people2;
select name, day(birthdate) -- 해당 일
from people2;
select name, year(birthdate) -- 해당 년
from people2;
select name, hour(birthtime) -- 해당 시간
from people2;
select name, minute(birthtime) -- 해당 분
from people2;
select name, second(birthtime) -- 해당 초
from people2;
'MySQL' 카테고리의 다른 글
MySQL - date_format, 시간차이 datediff, 날짜 더하기date_add 사용하기 (0) | 2022.12.07 |
---|---|
MySQL - 의 현재 Datetime 정보 가져오는 함수 curdate(), curtime(),now() (0) | 2022.12.07 |
MySQL not equal(~가 아닌 것) , not like (~를 포함하지 않은 것) 데이터 가져오기. (0) | 2022.12.07 |
MySQL - 값을 모두 더해주는 sum() , 값의 평균을 구해주는 avg() (0) | 2022.12.07 |
MySQL - count() 데이터 개수 확인하기,group by 그룹화 하여 데이터를 처리하기 (0) | 2022.12.07 |