Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with time and date.

Status
Not open for further replies.

Bartec

Programmer
Jan 21, 2005
54
PL
Hi

I have quite simple problem. I need to add to times for exmpl:

12:43:34 + 13:25:55

Is it possible??

Thanks for any response!

Bartec

 
Bartec,

Your problem might not be quite so simple depending upon what your problem means. Does your problem mean:

Option 1: "I am adding twelve hours, forty-three minutes, thirty-four seconds with thirteen hours, twenty-five minutes, and fifty-five seconds, yielding 26:09:29 total time"? or

Option 2: "I am adding 12:43:34 p.m. with 13:25:55 p.m."?

Unfortunately, Option 2 represents an undefined solution...it's like saying "What is today plus tomorrow?"

If, instead, you mean, "I am adding 12:43:34 p.m. plus its elapsed time to 13:25:55 p.m.", then that is a solvable problem.

If Option 1 is your need, then that is a very straightforward, solvable problem.

Which is your problem?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
a start
Code:
DECLARE
   v_hours     NUMBER;
   v_mins      NUMBER;
   v_seconds   NUMBER;
   v_first     VARCHAR2 (20) := '12:43:34';
   v_last      VARCHAR2 (20) := '13:25:55';
   v_result    VARCHAR2 (20);
BEGIN
   v_seconds := SUBSTR (v_first, 7, 2) + SUBSTR (v_last, 7, 2);
   v_mins := SUBSTR (v_first, 4, 2) + SUBSTR (v_last, 4, 2);
   v_hours := SUBSTR (v_first, 1, 2) + SUBSTR (v_last, 1, 2);

   IF v_seconds > 59
   THEN
      v_mins := v_mins + 1;
   END IF;

   SELECT CASE
             WHEN v_seconds > 59
                THEN v_seconds - 60
             ELSE v_seconds
          END
     INTO v_seconds
     FROM DUAL;

   IF v_mins > 59
   THEN
      v_hours := v_hours + 1;
   END IF;

   SELECT CASE
             WHEN v_mins > 59
                THEN v_mins - 60
             ELSE v_mins
          END
     INTO v_mins
     FROM DUAL;

   SELECT CASE
             WHEN v_hours > 23
                THEN v_hours - 24
             ELSE v_hours
          END
     INTO v_hours
     FROM DUAL;

   v_result := v_hours || ':' || v_mins || ':' || v_seconds;
   DBMS_OUTPUT.put_line (v_result);
END;

[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top