반응형
-- 날짜 자동등록
CREATE TABLE IF NOT EXISTS tablename (
[idx] INTEGER PRIMARY KEY AUTOINCREMENT,
[content] TEXT,
[send_state] INTEGER,
[send_date] DATETIME DEFAULT (DATETIME('now', 'localtime'))
);
-----------------------------
-- 2021-10-24 19:45:00 기준
-----------------------------
-- 국제표준시
SELECT DATETIME('now'); --> UTC(국제 표준시)
-- 한국표준시
SELECT DATETIME('now', 'localtime'); --> KST(한국 표준시, UCT+09:00)
-- 날짜만
SELECT DATE('now', 'localtime'); --> Result: KST 2021-10-24 --> Result: 20211024-194500
-- 날짜포맷 변경
SELECT strftime('%Y%m%d_%H%M%S', DATETIME('now', 'localtime')) as KSTCustom --> Result: 20211024_194500
-- 날짜검색용
SELECT DATETIME('now', '+1 year', 'localtime'); --> Result: 2022-10-24 19:45:00
SELECT DATETIME('now', '+1 month', 'localtime'); --> Result: 2021-11-24 19:45:00
SELECT DATETIME('now', '+1 day', 'localtime'); --> Result: 2021-10-25 19:45:00
SELECT DATETIME('now', '+1 hour', 'localtime'); --> Result: 2021-10-24 20:45:00
SELECT DATETIME('now', '+1 minutes', 'localtime'); --> Reuslt: 2021-10-24 19:46:00