728x90
오늘 특정 테이블에 VARCHAR 타입인 컬럼을 DATETIME 포맷으로 변경해 넣어야 하는 작업이 발생했다.
- a_list 테이블의 정보를 b_info 테이블로 옮겨야 했다.
"Sun, 16 Nov 2014 15:00:00 GMT"
"Fri, 09 Nov 2018 15:00:00 GMT"
이런 형식의 데이터를 STR_TO_DATE() 함수를 사용해 DATETIME 형태로 변환하여 넣을수 있었다.
INSERT INTO a_info (published_date)
SELECT STR_TO_DATE(b_list.publish_date, '%a, %d %b %Y') FROM b_list;
"Sun, 16 Nov 2014 15:00:00 GMT" >>> "2014-11-16"
"Fri, 09 Nov 2018 15:00:00 GMT" >>> "2018-11-09"
아래는 mysql 공식 홈페이지에서 발췌해온 표입니다. (대소문자를 구별합니다.)
Specifier | Description |
---|---|
%a | Abbreviated weekday name (Sun ..Sat ) |
%b | Abbreviated month name (Jan ..Dec ) |
%c | Month, numeric (0 ..12 ) |
%D | Day of the month with English suffix (0th , 1st , 2nd , 3rd , …) |
%d | Day of the month, numeric (00 ..31 ) |
%e | Day of the month, numeric (0 ..31 ) |
%f | Microseconds (000000 ..999999 ) |
%H | Hour (00 ..23 ) |
%h | Hour (01 ..12 ) |
%I | Hour (01 ..12 ) |
%i | Minutes, numeric (00 ..59 ) |
%j | Day of year (001 ..366 ) |
%k | Hour (0 ..23 ) |
%l | Hour (1 ..12 ) |
%M | Month name (January ..December ) |
%m | Month, numeric (00 ..12 ) |
%p | AM or PM |
%r | Time, 12-hour (hh:mm:ss followed by AM or PM ) |
%S | Seconds (00 ..59 ) |
%s | Seconds (00 ..59 ) |
%T | Time, 24-hour (hh:mm:ss ) |
%U | Week (00 ..53 ), where Sunday is the first day of the week; WEEK() mode 0 |
%u | Week (00 ..53 ), where Monday is the first day of the week; WEEK() mode 1 |
%V | Week (01 ..53 ), where Sunday is the first day of the week; WEEK() mode 2; used with %X |
%v | Week (01 ..53 ), where Monday is the first day of the week; WEEK() mode 3; used with %x |
%W | Weekday name (Sunday ..Saturday ) |
%w | Day of the week (0 =Sunday..6 =Saturday) |
%X | Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V |
%x | Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v |
%Y | Year, numeric, four digits |
%y | Year, numeric (two digits) |
%% | A literal % character |
% | x , for any “x ” not listed above |
728x90
'프로그래밍' 카테고리의 다른 글
IOS 앱 개인정보 처리 방침 (0) | 2020.01.26 |
---|---|
[GCP] Load balancing with firewall rules (0) | 2018.12.14 |
[GCP] bigquery nodejs example (0) | 2018.11.21 |
[javascript] 숫자 소수점 자리수 선택, 자르기 toFixed() (0) | 2018.03.30 |
[Mysql] CONCAT 함수 / 문자열 연결, 합치기 (0) | 2018.03.19 |