Home » SQL & PL/SQL » SQL & PL/SQL » Subtract hours from current date
Subtract hours from current date [message #147155] Tue, 15 November 2005 23:49 Go to next message
ak_ora
Messages: 16
Registered: October 2005
Location: India
Junior Member
Hi!

select to_char(sysdate, 'HH24:MI:SS') as "Current_Time" from dual

The above query gives current time, how to subtarct 12 hours from
current time.

Thanks in advance


AK.
Re: Subtract hours from current date [message #147157 is a reply to message #147155] Wed, 16 November 2005 00:03 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member
SQL>  select to_char(sysdate, 'dd-mon-yy HH24:MI:SS') as "Current_Time" from dual;

Current_Time
------------------
16-nov-05 11:32:56

SQL> select to_char((sysdate-12/24), 'dd-mon-yy HH24:MI:SS') as "Current_Time" from dual;

Current_Time
------------------
15-nov-05 23:32:46


Re: Subtract hours from current date [message #147177 is a reply to message #147157] Wed, 16 November 2005 02:28 Go to previous message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
To clarify tarun's answer: date calculations are in units of days:
sysdate - 1 = sysdate - 1 day = sysdate - 24 hours.
sysdate - 12/24(*1 day) = sysdate - (12/24)(*24 hours) = sysdate - 12 hours.

MHE

[Updated on: Wed, 16 November 2005 02:29]

Report message to a moderator

Previous Topic: about top N analysis
Next Topic: Query to retrieve all the duplicate names from a table
Goto Forum:
  


Current Time: Sat Sep 06 06:06:42 CDT 2025