mysql, mariaDB 에서 날짜/시간 더하기/빼기
# 더하기
date_add([기준날짜], interval [수치] [년/월/일/시/분/초])
# 빼기
date_sub([기준날짜], interval [수치] [년/월/일/시/분/초])
/*
- 연: year / 월: month / 일: day
- 시: hour / 분: minute / 초: second
*/
select convert_tz(now(), 'utc', 'asia/seoul') 'now_kst',
date_add(convert_tz(now(), 'utc', 'asia/seoul'), interval 1 hour) '1_hour_later';
/* result
+---------------------+---------------------+
|now_kst |1_hour_later |
+---------------------+---------------------+
|2022-06-16 10:30:33.0|2022-06-16 11:30:33.0|
+---------------------+---------------------+
*/
select convert_tz(now(), 'utc', 'asia/seoul') 'now_kst',
date_sub(convert_tz(now(), 'utc', 'asia/seoul'), interval 1 year) '1_year_ago';
/* result
+---------------------+---------------------+
|now_kst |1_year_ago |
+---------------------+---------------------+
|2022-06-16 10:33:30.0|2021-06-16 10:33:30.0|
+---------------------+---------------------+
*/