Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Calculate Time

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
samedesh
Currently Banned

New User


Joined: 22 May 2007
Posts: 46
Location: India

PostPosted: Thu Dec 23, 2010 12:33 pm    Post subject: Calculate Time
Reply with quote

Hello All,

I am writing a cobol pgm and have the requirement to perform the addition on time variable. Is their any DB2 inbuilt utility which can perform computations on time.

I want 09:00 + 00:15 = 09:15, something like this.

Thanks
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Dec 23, 2010 12:59 pm    Post subject:
Reply with quote

If your module is already executing SQL,
then simply adding some sql to perform date time arithmetic (see sql manuals - IBM manuals button at top of page)
is easy.

if your module does not have a db2 requirement other than your date time arithmetic,
then look at the LE manuals
this means that you will have to make several calls
  • convert date/time
  • subtract converted values
  • convert the difference from the subtraction to a date time
now this sounds like a lot of trouble,
but a programmers time is nowhere as expensive as db2 resources.

and if your requirement is only a simple addition/subtraction of time
without worrying about date
is very simple,
probably already on the web someplace.
Back to top
View user's profile Send private message
samedesh
Currently Banned

New User


Joined: 22 May 2007
Posts: 46
Location: India

PostPosted: Thu Dec 23, 2010 3:03 pm    Post subject: Reply to: Calculate Time
Reply with quote

Hi,

I tried following query for substraction and it worked fine

SELECT TIME(Column A) - TIME(Column B)
FROM Table

But when I tried for addition it is giving me -171 sqlcode.

SELECT TIME(Column A) + TIME(Column B)
FROM Table

Please guide.

Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Dec 23, 2010 3:45 pm    Post subject:
Reply with quote

as you can see from the FM you can find the difference between data/time/timestamps but you can only increment or decrement them.

and the results of the subtraction is the interval in time units. not an actual time.

best way is
  • RTFM
  • add or subtract a time interval (again refer to the manual) from a date/time datatype to return a modified date/time datatype
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Dec 23, 2010 4:02 pm    Post subject:
Reply with quote

you can also try these sql statements and learn about date/time arithmetic

Code:

SELECT CURRENT_TIME
  FROM SYSIBM.SYSDUMMY1
;
SELECT CURRENT_TIME + 1 HOUR
     , CURRENT_TIME
  FROM SYSIBM.SYSDUMMY1
;
SELECT ((CURRENT_TIME + 1 HOUR) + 1 MINUTES) + 1 SECONDS
     , CURRENT_TIME
  FROM SYSIBM.SYSDUMMY1
;
SELECT (((CURRENT_TIME + 1 HOUR) + 1 MINUTES) + 1 SECONDS) + 1 DAY
     , CURRENT_TIME
  FROM SYSIBM.SYSDUMMY1
;
Back to top
View user's profile Send private message
samedesh
Currently Banned

New User


Joined: 22 May 2007
Posts: 46
Location: India

PostPosted: Thu Dec 23, 2010 4:44 pm    Post subject: Reply to: Calculate Time
Reply with quote

I cannot hardcode the values as both are coming from columns of a table.
No idea what values may come. I have to put this in the cobol code which is having other DB2 queries also.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Thu Dec 23, 2010 8:20 pm    Post subject:
Reply with quote

RTFM about date-time functions
you've got hour(), minute(), second() ,midnight_seconds() ,... to work with.

f.e. : colA + hour(colB) hours
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Date and time format in CICS Chandru3183 CICS 2 Sat Mar 18, 2017 12:46 pm
No new posts How to get current date -1 and curren... murali.andaluri DFSORT/ICETOOL 3 Wed Mar 08, 2017 2:09 pm
No new posts CICS transaction slow response time vasanthz All Other Mainframe Topics 3 Thu Jan 19, 2017 1:31 am
No new posts DD DUMMY & CPU TIME Nileshkul Testing & Performance analysis 16 Mon Dec 19, 2016 11:35 pm
This topic is locked: you cannot edit posts or make replies. Get a job submitted itself every time... arunsoods JCL & VSAM 3 Tue Nov 22, 2016 4:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us