FB日期时间操作

 

查询2007年度以后的,12月份以上的数据记录,datetime为timestamp字段

select * from tableblob where extract(month from datetime)=12 and extract(year from datetime)>2007

查询不重复的(年份+月份)组合,datetime为timestamp字段

select distinct (extract(year from datetime)||extract(month from datetime)) from tableblob

获取当前年(其它如year,month,day,hour,minute,second,week,weekday等,都可以获取):

select extract(year from current_timestamp) from rdb$database

select extract(week from current_timestamp) from rdb$database

日期时间操作
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

posted on 2010-07-30 10:04  A.wei  阅读(554)  评论(0编辑  收藏  举报