If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Adding minutes to timestamp variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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...
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 3,385
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
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Dec 2009
Posts: 2
Re: Adding minutes to timestamp variable

Thanks for the response .....

Will surely try this one now
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 3,385
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.
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On