我想在firebird上获得类似于Javascript上的GetTime的时间 我创造了一个,但每天的时差增量并不准确
CREATE PROCEDURE GETTIMEINMILLISECONDS
RETURNS (
MILL VARCHAR(50)
)
AS
DECLARE VARIABLE VAR_PARAM INTEGER;
BEGIN
select
(((extract(year from current_timestamp)
-extract(year from cast('01/01/1970 00:00:00' as timestamp))) * 31536000000) +
(extract(month from current_timestamp) * 2592000000) +
(extract(day from current_timestamp) * 8640000) +
(extract(Hour from current_timestamp) * 3600000) +
(extract(minute from current_timestamp) * 60000) +
(extract(second from current_timestamp) * 1000))-192960000
from rdb$database into :Mill;
suspend;
END
;
答案 0 :(得分:3)
在Firebird 2.1及更高版本上,您可以使用
select DATEDIFF(second, timestamp '1/1/1970 00:00:00', current_timestamp)
from rdb$database
对于早期版本,您可以使用FreeAdhocUDF中的UDF F_AGEINSECONDS:
select F_AGEINSECONDS('1/1/1970 00:00:00', current_timestamp) from
rdb$database
请参阅http://tech.groups.yahoo.com/group/firebird-support/message/102699
如果您不在GMT,则需要通过将时区偏移添加到时间戳来计算当前时区。例如,对于CEST(+2:00),您需要使用:
select DATEDIFF(second, timestamp '1970-01-01 02:00:00', current_timestamp)
from rdb$database
(注意我在这里切换到ISO-8601日期格式)