Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find out differences between two timestamps and extract only hours and minutes

How to find out the difference between two timestamps and get only hours and minutes from the difference? I tried using the extract function or doing straight subtraction but I am not getting the expected result.

select (to_timestamp('29-09-22 2:27:48.696000000 PM +05:30') - systimestamp)col from dual;

DB Version: Oracle SQL Developer (18c)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use EXTRACT:

SELECT EXTRACT(DAY FROM diff)*24 + EXTRACT(HOUR FROM diff) AS hours,
       EXTRACT(MINUTE FROM diff) AS minutes
FROM   (
  select TIMESTAMP '2022-09-29 14:27:48.696000000 +05:30' - systimestamp AS diff
  from   dual
);

Which outputs:

HOURS MINUTES
23 41

fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading