0

It shows it in very bad way but I need to be Hour:Minutes.

SELECT DepName, ARRSTATIONNAME,  VEHICLENUMBER, ARRVTIME - DEPTIME FROM VEHICLENUMBER...

ARRVTIME - DEPTIME is where I need to do formatting because rn I am getting

+000000000 02:28:00.000000
1
  • Please post sample data and your desired output. I have edited your question to format it, please take some time and follow posting guidelines. Please see How to ask a question Commented May 8, 2020 at 18:42

1 Answer 1

2

Looks like you're dealing with timestamps. If that's so, have a look at this example:

Sample table:

SQL> create table test (arrvtime timestamp, deptime timestamp);

Table created.

SQL> insert into test values (systimestamp, systimestamp - 0.2);

1 row created.

SQL> select * From test;

ARRVTIME                        DEPTIME
------------------------------- -------------------------------
08.05.20 21:04:50,508000        08.05.20 16:16:50,000000

Query you might need:

SQL> select arrvtime - deptime diff,
  2         extract(hour from arrvtime - deptime) hours,
  3         extract(minute from arrvtime - deptime) minutes,
  4         --
  5         -- what you want
  6         extract(hour  from arrvtime - deptime) ||':'||
  7         extract(minute from arrvtime - deptime) result
  8  from test;

DIFF                                 HOURS    MINUTES RESULT
------------------------------- ---------- ---------- ------
+000000000 04:48:00.508000               4         48 4:48

SQL>
Sign up to request clarification or add additional context in comments.

2 Comments

Tho for little interest how do you deal with minutes when they are single digit like 3:2?
You're welcome. As of your last question: EXTRACT would extract them as well, no difference. If you meant how to format it so that e.g. 2 minutes are displayed as 02 (with a leading zero), then use LPAD: lpad(extract(minute from diff), 2, '0')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.