## Forum Stats

• 3,838,418 Users
• 2,262,359 Discussions

Discussions

# How to calculate time difference between two columns?

Member Posts: 277 Blue Ribbon
edited Dec 10, 2010 5:31AM
Hi,

How to calculate time difference between two dates columns?

thx

Edited by: user12007410 on Dec 10, 2010 2:03 AM
Tagged:

• Member Posts: 1,029 Gold Badge
SELECT (col1 - col2) AS difference from table_name

It will give you output in Days.

Regards
Arun
• Member Posts: 3,185 Gold Trophy
try this, u have have to modify it a little

http://nimishgarg.blogspot.com/2010/08/oracle-sql-date-difference-in-days.html

• Member Posts: 277 Blue Ribbon
Dear,

i need output in minutes
• Member Posts: 1,029 Gold Badge
edited Dec 10, 2010 5:12AM
Then use this

SELECT (col1 - col2)*24*60 AS difference_in_minutes from table_name

like this
```SQL>SELECT (SYSDATE - TRUNC(SYSDATE))*24*60 difference_in_minutes
2    FROM DUAL;

DIFFERENCE_IN_MINUTES
---------------------
251.533333

SQL>```
Regards
Arun

Edited by: Arun Kumar Gupta on Dec 10, 2010 3:41 PM
• Member Posts: 277 Blue Ribbon
Hi arun,

Can you please explain query and its output for me?

thx
• Member, Moderator Posts: 42,130 Red Diamond
What needs explaining?

You take one date away from another wich gives you the difference in number of days (including fractions). Multiply that value by the number of minutes in a day (24 hours * 60 minutes) to find out what it is in minutes.

Basic mathematics.
• Member Posts: 753
Hi,

Try this
`SELECT TO_TIMESTAMP(COL1) - TO_TIMESTAMP(COL2) FROM TABLE_NAME;`
cheers

VT
This discussion has been closed.