데이터베이스/Firebird
Firebird에서 Timestamp형에서 날짜와 시간을 분리하기
띠리
2009. 1. 7. 16:39
Timestamp형에서 날짜와 시간을 분리하는 SQL
위의 SQL문을 쓰면 Timestamp형 필드를 날짜형과 시간형으로 바꾸어준다.
TIMESTAMP형 WHERE문
Timestamp에서 WHERE문을 쓸 때는 날짜만 써도 된다.
아마도 날짜만 입력하면 뒤에 자동으로 00:00:00으로 처리하는 것 같다.
SELECT
cast(extract(day from myTIMESTAMP)|| '.'||
extract(month from myTIMESTAMP)|| '.'||
extract(year from myTIMESTAMP) as date) ,
cast(extract(Hour from myTIMESTAMP)|| ':'||
extract(Minute from myTIMESTAMP)|| ':'||
extract(Second from myTIMESTAMP) as Time)
FROM MyLOG
cast(extract(day from myTIMESTAMP)|| '.'||
extract(month from myTIMESTAMP)|| '.'||
extract(year from myTIMESTAMP) as date) ,
cast(extract(Hour from myTIMESTAMP)|| ':'||
extract(Minute from myTIMESTAMP)|| ':'||
extract(Second from myTIMESTAMP) as Time)
FROM MyLOG
위의 SQL문을 쓰면 Timestamp형 필드를 날짜형과 시간형으로 바꾸어준다.
TIMESTAMP형 WHERE문
SELECT * FROM MyLOG
WHERE myTIMESTAMP > '2009-1-7 12:00:00'
SELECT * FROM MyLOG
WHERE myTIMESTAMP > '2009-1-1'
WHERE myTIMESTAMP > '2009-1-7 12:00:00'
SELECT * FROM MyLOG
WHERE myTIMESTAMP > '2009-1-1'
Timestamp에서 WHERE문을 쓸 때는 날짜만 써도 된다.
아마도 날짜만 입력하면 뒤에 자동으로 00:00:00으로 처리하는 것 같다.