2011년 6월 7일 화요일

SQLite - Date, Time Functions

Functions
date( timestring, modifier, modifier, ...)
time( timestring, modifier, modifier, ...)
datetime( timestring, modifier, modifier, ...)
julianday( timestring, modifier, modifier, ...)
strftime( format, timestring, modifier, modifier, ...)


timestring

YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
DDDD.DDDD

modifier

NNN days
NNN hours
NNN minutes
NNN.NNNN seconds
NNN months (see #551 and [1163] )
NNN years (see #551 and [1163] )
start of month
start of year
start of week (withdrawn -- will not be implemented)
start of day
weekday N (see #551 and [1163] )
unixepoch
localtime
utc



현재의 날짜를 알고 싶으면
select date('now');

현재 기준 20일 후의 날짜를 알고 싶으면
select date('now', '20 days');


현재 기준 20일 이전의 날짜를 알고 싶으면
select date('now', '-20 days');

이렇게 조회를 하면 'YYYY-MM-DD' 형태로 조회가 된다.

특정한 양식으로 조회 결과를 얻는다던가, 아니면 일자, 월, 년도만 따로 조회를 하고 싶다면, strftime을 사용하면 된다.

strftime 함수의 format 파라미터에 아래 파라 미터들을 조합해서 원하는 형태로 날짜, 시간을 조회 할 수 있다.

%d  day of month
%f  ** fractional seconds  SS.SSS
%H  hour 00-24
%j  day of year 001-366
%J  ** Julian day number
%m  month 01-12
%M  minute 00-59
%s  seconds since 1970-01-01
%S  seconds 00-59
%w  day of week 0-6  sunday==0
%W  week of year 00-53
%Y  year 0000-9999
%%  %

현재 일시를 'YYYY/MM/DD HH24:MI' 형태로 조회하고 싶다면
select strftime('%Y/%m/%d %H:%M', 'now');


댓글 없음:

댓글 쓰기