Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle - Best SELECT statement for getting the difference in minutes between two DateTime columns?

Tags:

I'm attempting to fulfill a rather difficult reporting request from a client, and I need to find away to get the difference between two DateTime columns in minutes. I've attempted to use trunc and round with various formats and can't seem to come up with a combination that makes sense. Is there an elegant way to do this? If not, is there any way to do this?

like image 580
AJ. Avatar asked Oct 15 '08 20:10

AJ.


People also ask

How can I find the difference between two timestamps in Oracle?

To calculate the difference between the timestamps in Oracle, simply subtract the start timestamp from the end timestamp (here: arrival - departure ). The resulting column will be in INTERVAL DAY TO SECOND .

How do I get the difference between two dates and minutes in SQL?

DATEDIFF() is a basic SQL Server function that can be used to do date math. Specifically, it gets the difference between 2 dates with the results returned in date units specified as years, months days, minutes, seconds as an int (integer) value.

How do I find the difference in time between two columns in SQL?

To calculate the difference between the arrival and the departure in T-SQL, use the DATEDIFF(datepart, startdate, enddate) function. The datepart argument can be microsecond , second , minute , hour , day , week , month , quarter , or year .

How can I find the difference between two dates in Oracle?

Answer: Oracle supports date arithmetic and you can make expressions like "date1 - date2" using date subtraction to get the difference between the two dates.


1 Answers

SELECT date1 - date2   FROM some_table 

returns a difference in days. Multiply by 24 to get a difference in hours and 24*60 to get minutes. So

SELECT (date1 - date2) * 24 * 60 difference_in_minutes   FROM some_table 

should be what you're looking for

like image 192
Justin Cave Avatar answered Oct 05 '22 16:10

Justin Cave