Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Post Adding minutes to timestamp variable

    Hiall,

    I have a timestamp variable having some timestamp information. I want to add some minutes to the time represented by the timestamp variable.
    The minutes that I am adding is stored in a variable. How do achieve this in DB2...

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Code:
    ------------------------------ Commands Entered ------------------------------
    SELECT cola
         , colx
         , cola + colx minutes AS "cola + colx minutes"
      FROM (VALUES CURRENT TIMESTAMP) AS table_a(cola)
         , (VALUES 5 ) AS table_b(colx)
    ;
    ------------------------------------------------------------------------------
    
    COLA                       COLX        cola + colx minutes       
    -------------------------- ----------- --------------------------
    2009-12-23-15.24.10.814000           5 2009-12-23-15.29.10.814000
    
      1 record(s) selected.
    Please see DB2 Basics: Fun with Dates and Times

  3. #3
    Join Date
    Dec 2009
    Posts
    2

    Re: Adding minutes to timestamp variable

    Thanks for the response .....

    Will surely try this one now

  4. #4
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Another example:
    Code:
    ------------------------------ Commands Entered ------------------------------
    DECLARE GLOBAL TEMPORARY TABLE a(cola TIMESTAMP, colb INTEGER, colc TIMESTAMP);
    ------------------------------------------------------------------------------
    DB20000I  The SQL command completed successfully.
    
    ------------------------------ Commands Entered ------------------------------
    BEGIN ATOMIC
    DECLARE val_a, val_c TIMESTAMP;
    DECLARE val_b INTEGER;
    SET val_a = CURRENT TIMESTAMP;
    SET val_b = 5;
    SET val_c = val_a + val_b minutes;
    INSERT INTO SESSION.a
    VALUES (val_a, val_b, val_c);
    END@
    ------------------------------------------------------------------------------
    DB20000I  The SQL command completed successfully.
    
    ------------------------------ Commands Entered ------------------------------
    SELECT * FROM SESSION.a@
    ------------------------------------------------------------------------------
    
    COLA                       COLB        COLC                      
    -------------------------- ----------- --------------------------
    2009-12-23-15.39.26.651000           5 2009-12-23-15.44.26.651000
    
      1 record(s) selected.

  5. #5
    Join Date
    Jan 2009
    Location
    Zoetermeer, Holland
    Posts
    746
    You mean this?
    Code:
    C:\>set MINUTES=5
    
    C:\>db2 select current_timestamp as now, current_timestamp + %MINUTES% minutes as near_future from sysibm.sysdummy1
    
    NOW                        NEAR_FUTURE
    -------------------------- --------------------------
    2009-12-23-07.51.23.426000 2009-12-23-07.56.23.426000

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •