R&D/database

mysql datetime

sunshout 2018. 10. 6. 18:39

MySQL 에서 datetime 이라는 data type 이 존재한다.

형식은 YYYY-MM-DD HH:MM:SS


MySQL stores TIMESTAMP in UTC value. However, MySQL stores the DATETIME value as is without timezone. Let’s see the following example.

First, set the timezone of the current connection to +00:00.


GMT로 저장된 데이터를 Asia/Seoul로 변경해서 출력하고 싶을 때

SELECT CONVERT_TZ(displaytime,'GMT','right/Asia/Seoul');


Where 절에서 시간을 변경해서 쿼리를 하고 싶을 때는

select CONVERT_TZ(creation_time,'GMT','right/Asia/Seoul') from accounts where CONVERT_TZ(creation_time,'GMT','right/Asia/Seoul') >= '2018-10-06';



참고: 

http://www.mysqltutorial.org/mysql-datetime/

https://stackoverflow.com/questions/15017799/how-to-convert-utc-date-to-local-time-zone-in-mysql-select-query