Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
Tags
- 최솟값
- 분류 결과표
- wcss
- IN
- list
- DataAccess
- count()
- 반복문
- nan
- analizer
- DataFrame
- numpy
- pandas
- sklearn
- 최댓값
- 덴드로그램
- string
- hierarchical_clustering
- append()
- del
- matplotlib
- dendrogram
- function
- insert()
- Dictionary
- Machine Learning
- data
- len()
- Python
- elbow method
Archives
- Today
- Total
개발공부
[MySQL] 시간 관련 데이터 타입 date, time, datetime, timestamp 본문
아래와 같은 형식으로 저장하면 MYSQL에서
시간관련 데이터 타입으로 인식된다.
date
YYYY-MM-DD
time
HH:MM:SS
datetime
YYYY-MM-DD HH:MM:DD
생성 예제
insert into people
(name, birthdate, birthtime, birthdt)
values
('Padma', '1988-11-11', '10:07:35', '1988-11-11 10:07:35'),
('Larry', '1994-04-22', '04:10:42', '1994-04-22 04:10:42');
select * from people;

timestamp
날짜를 숫자로 표현, 1970년 1월 1일 자정을 0으로 시작하여 지금까지 흘러온 초를 뜻한다.
타임 스탬프를 이용해 생성시간, 갱신시간 컬럼 생성 예제
CREATE TABLE 'comments' (
'id' INT UNSIGNED NOT NULL AUTO_INCREMENT,
'content' VARCHAR(100) NULL,
'created_at' TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
'updated_at' TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`));
데이터 추가하기
insert into comments
(content)
values
('안녕하세요');
select * from comments;

insert into comments
(content)
values
('반가워요');
select *
from comments;

위와 같이 데이터를 추가하면 created_at, updated_at이 추가한 시간으로 저장된다.
데이터 갱신하기
update comments
set content = '잘 부탁드려요.'
where id = 2;
select * from comments;

위와 같이 update를 하면 updated_at의 시간이 갱신한 시간으로 변경됨을 알 수 있다.
'Database > MySQL' 카테고리의 다른 글
| [MySQL] 시간 데이터 년, 월, 일, 시, 분, 초, 요일 가져오기 (0) | 2022.05.16 |
|---|---|
| [MySQL] 현재 시간과 관련된 함수 curdate(), curtime(), now() (0) | 2022.05.16 |
| [MySQL] 데이터 별로 묶기 group by, 데이터의 개수 count(), 합계 sum() 최댓값 max(), 최솟값 min(), 평균 값 avg() (0) | 2022.05.16 |
| [MySQL] 원하는 행 가져오기 limit, 문자열 검색 like (0) | 2022.05.16 |
| [MySQL] 데이터 중복 없이 선택 distinct, 데이터 정렬 order by (0) | 2022.05.16 |