2015년 11월 22일 일요일

DATETIME and TIMESTAMP

1. DATA Type

DATETIME and TIMESTAMP datatype have year,month,day,hour,minute and seconds. Additionally, They can save fraction of second. They use data format with YYYY-MM-DD HH:MM:SS[.fraction]. DATETIME can save value from '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999' . TIMESTAMP can save value from '1970-01-01 00:00:01.000000' UTC to '2038-01-19 03:14:07.99999' UTC.

2. Different DATETIME and TIMESTAMP 

DATETIME have no timezone information. TIMESTAMP have timezone information with time_zone system  variables. In detail,  TIMESTAMP have date and time data in UTC timezone. So, Before saving date and time data, MySQL convert timezone to UTC.

3. Setting default value 

After MySQL Version 5.6, DATETIME setting default time value.

CREATE TABLE t1 (
  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);


댓글 없음:

댓글 쓰기