how to get today date in YYYYMMDD in firebird

后端 未结 4 1562
情深已故
情深已故 2021-01-25 12:57

how to get today date in YYYYMMDD in firebird, I had a look on following but could not figured how to write this.

相关标签:
4条回答
  • 2021-01-25 13:23

    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
    

    OUTPUT IS: YYYYMMDD HHMMSS

    0 讨论(0)
  • 2021-01-25 13:24

    This is a fully version (in Integer)

    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
    

    This is a fully version (in 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
    
    0 讨论(0)
  • 2021-01-25 13:43

    This Should work.

    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;
    
    0 讨论(0)
  • 2021-01-25 13:48

    I think you can do:

    select replace(cast(cast('Now' as date) as varchar(10)), '-', '')
    from rdb$database 
    
    0 讨论(0)
提交回复
热议问题