반응형
  • DB timezone설정이 utc이면 current_timestamp=utc_timestamp이지만, 아니면 다름, 즉, current_timestamp = now() != utc_timestamp
    • select current_timestamp; -- 2022-04-22 16:06:16
      select current_time; -- 16:06:08
      select current_date; -- 2022-04-22
      select utc_timestamp; -- 2022-04-22 07:06:38
      select utc_time; -- 07:06:52
      select utc_date; -- 2022-04-22
      select now(); -- 2022-04-22 16:07:17
  • date, time, timestamp 차이
    • date: 날짜만 보여주고 날짜 정보까지만 가짐
    • time: 시간만 보여주지만 날짜 + 시간정보 모두 가짐
    • timestamp: 시간 full로 보여줌
    • 다음과 같이 function으로도 사용가능
select current_date, date(current_date), time(current_date), timestamp(current_date);
select current_time, date(current_time), time(current_time), timestamp(current_time);
select current_timestamp, date(current_timestamp), time(current_timestamp), timestamp(current_timestamp);
  • 날짜 더하기빼기: +1로 일단위,초단위 가능, 시간단위로 하려면 date_add 써야함
    • select utc_timestamp -- 2022-04-22 07:17:22
      union all
      select utc_timestamp + 1 -- 20220422071651 (+ 1 second)
      union all
      select utc_time + 1 -- 71651 (+ 1 second)
      union all
      select utc_date + 1 -- 20220423 (+ 1 day)
    • select current_timestamp() -- 2022-04-22 16:21:07
      union all
      select current_timestamp + 1 -- 20220422162108 (+ 1 second)
      union all
      select current_time + 1 -- 162108 (+ 1 second)
      union all
      select current_date + 1 -- 20220423 (+ 1 day)
    • select DATE_ADD(current_timestamp, interval 20 hour) -- 2022-04-23 00:00:00
      select DATE_ADD(current_date, interval 1 day)-- 2022-04-23
      select DATE_ADD(now(), interval 1 day)-- 2022-04-23 16:10:08
반응형

'db' 카테고리의 다른 글

mysql 한글깨짐  (0) 2022.04.26
mysql console 접속  (0) 2022.04.26
우분투 18.04 MongoDB 설치 및 구성  (0) 2022.04.18
mysql remote 접속허용  (0) 2022.04.14
mysql numeric type  (0) 2020.11.05

+ Recent posts