Q
Problem solve Get help with specific problems with your technologies, process and projects.

Substracting two dates and getting value in hours

How can I subtract two dates and get the value in hours (i.e. date-date = hours)?
Say you have a table holds_date with an end_date and start_date columns of date data types.

If you say

SELECT (END_DATE-START_DATE)*24

 FROM HOLD_DATES

you will get the desired outcome.

Please note if a date field is populated with just the date component of date time, then the default for the time is midnight.

So, please ensure the data is correct, you can view the date component of a date field by formatting the output. This will ensure that when you are subtracting date/time your time components are correct.

SELECT TO_CHAR(END_DATE, 'MM/DD/YYYY HH24:MI')

FROM HOLD_DATES

Dig Deeper on Using Oracle PL-SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close