database

MySQL - timestamp 컬럼 시간 0으로 업데이트 (datetime to date)

codeManager 2022. 8. 11. 18:49
반응형

1. DATE_FORMAT

날짜를 지정한 형식으로 출력해주는 함수입니다.

 

 

2. DATE_FORMAT 구분 기호

구분기호 역할
%Y 4자리 년도
%y 2자리 년도
%M 긴 월 (영문)
%m 숫자 월(두자리)
%d 일자 (두자리)
%T hh:mm:SS
%H 시간(24시간)
%S

 

https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format

 

MySQL :: MySQL 5.7 Reference Manual :: 12.7 Date and Time Functions

12.7 Date and Time Functions This section describes the functions that can be used to manipulate temporal values. See Section 11.2, “Date and Time Data Types”, for a description of the range of values each date and time type has and the valid formats

dev.mysql.com

 

MySQL에서 timestamp 컬럼에서 날짜값은 그대로 두고 시간값을 00:00:00으로 업데이트 하는 방법입니다.

update person set birth = DATE_FORMAT(birth, ‘%Y-%m-%d 00:00:00’);

person 테이블의 birth(timestamp) 컬럼의 datetime 값에서 날짜값만 유지하고 시간값은 0으로 업데이트합니다.

반응형