Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtract one hour from datetime rather than one day

I have a datetime column in Oracle (MM/DD/YYYY HH:MM:SS AM/PM) but when I do this:

SELECT MAX(D_DTM)-1 FROM tbl1

...it goes back a day. How do I remove one hour from the column rather than one day?

I've also noticed that the datetime records for 12AM look like MM/DD/YYYY and not MM/DD/YYYY 00:00:00; I'm not sure if that matters.

like image 372
lightweight Avatar asked Apr 18 '13 13:04

lightweight


2 Answers

Randy's answer is good, but you can also use intervals:

SELECT MAX(D_DTM)- interval '1' hour FROM tbl1
like image 110
A.B.Cade Avatar answered Nov 07 '22 17:11

A.B.Cade


Its simple.

sysdate - 5/(24*60*60) --> Subtracts 5 seconds from systime

sysdate - 5/(24*60) --> Subtracts 5 minutes from systime

sysdate - 5/(24) --> Subtracts 5 hours from systime

Hence

select (sysdate - (1/24)) from dual

like image 44
Ankit Kachchhi Avatar answered Nov 07 '22 17:11

Ankit Kachchhi