最近在使用Firebird數據作 一項目,使用FireBird邊用邊學。(如下轉貼)spa
查詢2007年度之後的,12月份以上的數據記錄,datetime爲timestamp字段.net
select * from tableblob where extract(month from datetime)=12 and extract(year from datetime)>2007get
查詢不重複的(年份+月份)組合,datetime爲timestamp字段table
select distinct (extract(year from datetime)||extract(month from datetime)) from tableblobast
獲取當前年(其它如year,month,day,hour,minute,second,week,weekday等,均可以獲取):class
select extract(year from current_timestamp) from rdb$databasedate
select extract(week from current_timestamp) from rdb$databaseselect
日期時間操做
FB中得到時間的操做符:
CURRENT_DATE : 當前日期
CURRENT_TIME : 當前時間
CURRENT_TIMESTAMP: 當前的日期時間,也稱時間戳
從時間類型中得到信息的操做符:
EXTRACT(.. FROM ..)
Select EXTRACT(.. FROM ..) from RDB$DATABASE
若是返回值不存在時間值中會報錯.
時間類型中的年份 EXTRACT(YEAR from CURRENT_TIMESTAMP); EXTRACT(YEAR from CAST('2005-8-1' as Date))=2005
月份 EXTRACT(MONTH from CURRENT_TIMESTAMP); EXTRACT(MONTH from CAST('2005-8-1' as Date))=8
日期 EXTRACT(DAY from CURRENT_TIMESTAMP); EXTRACT(DAY from CAST('2005-8-1' as Date))=1
天數 EXTRACT(YEARDAY from CURRENT_TIMESTAMP) ;EXTRACT(YEARDAY from CAST('2005-8-1' as Date))=212
星期幾 EXTRACT(YEARDAY from CURRENT_TIMESTAMP); EXTRACT(DAY from CAST('2005-8-1' as Date))=1
CAST('Now' as Timestamp) 至關於 Current_Timestamp
CAST('ToDay' as Date) 今天的日期
CAST('yesterday' as Date') 昨天的日期方法
如何取兩個日期相差的年數 |
在FIREBIRD中怎樣才能取得兩個日期字段相差的年數,好比2000-05-3與2007-09-12相差幾年,有比(cast('2000-05-03' as date)-cast('2007-09-12' as date))/365更好的方法嗎? http://www.firebird.net.cn/forum_view.asp?forum_id=1&view_id=379&page=1 |
select extract(year from cast('2008-1-1' as date)) -extract(year from cast('2007-1-1' as date))from rdb$database