如何获得今天在火鸟YYYYMMDD的日期

时间:2014-01-20 17:31:09

标签: sql firebird firebird2.5

今天如何在火鸟的YYYYMMDD中获取日期,我看了following,但无法想出如何写这个。

4 个答案:

答案 0 :(得分:7)

我认为你可以做到:

select replace(cast(cast('Now' as date) as varchar(10)), '-', '')
from rdb$database 

答案 1 :(得分:3)

这是一个完整版本(整数)

select  Extract(year FROM cast('NOW' as date))*10000 +
        Extract(month FROM cast('NOW' as date))*100 +
        Extract(day  FROM cast('NOW' as date)) from rdb$database

这是一个完整版本(在VARCHAR中)

select  CAST(Extract(year FROM cast('NOW' as date))*10000 +
        Extract(month FROM cast('NOW' as date))*100 +
        Extract(day  FROM cast('NOW' as date)) AS VARCHAR(8)) from rdb$database

答案 2 :(得分:3)

IN FIREBIRD v2.5.5:

SELECT    LPAD( EXTRACT( YEAR FROM CURRENT_TIMESTAMP ), 4, '0' ) ||
          LPAD( EXTRACT( MONTH FROM CURRENT_TIMESTAMP ), 2, '0' ) ||
          LPAD( EXTRACT( DAY FROM CURRENT_TIMESTAMP ), 2, '0' ) || ' ' ||
          LPAD( EXTRACT( HOUR FROM CURRENT_TIMESTAMP ), 2, '0' ) ||
          LPAD( EXTRACT( MINUTE FROM CURRENT_TIMESTAMP ), 2, '0' ) || 
          LPAD( TRUNC( EXTRACT( SECOND FROM CURRENT_TIMESTAMP ) ), 2, '0' )
FROM      rdb$database

输出为: YYYYMMDD HHMMSS

答案 3 :(得分:1)

这应该有用。

CREATE TABLE tab( t time, d date, ts timestamp );
INSERT INTO tab(t,d,ts) VALUES ('14:59:23', '2007-12-31', '2007-12-31 14:59');

SELECT CAST(CAST(d as varchar(10)))
FROM tab;