Home » SQL & PL/SQL » SQL & PL/SQL » how to add hours to date
how to add hours to date [message #185821] Thu, 03 August 2006 14:58 Go to next message
dhanisetti
Messages: 7
Registered: July 2006
Junior Member
Hi Experts,

I want to add one hour to date which takes input from user

I used the below query

select &UserDate + 1/24 from dual

It is working but not giving the same result as the following query gives.

select sysdate + 1/24 from dual

Please help on this.

Thanks
Dhani


Re: how to add hours to date [message #185825 is a reply to message #185821] Thu, 03 August 2006 15:15 Go to previous messageGo to next message
scottwmackey
Messages: 505
Registered: March 2005
Senior Member
Try this

select to_date('&UserDate', 'YOUR_FORMAT') + 1/24 from dual
Re: how to add hours to date [message #185829 is a reply to message #185825] Thu, 03 August 2006 15:39 Go to previous messageGo to next message
dhanisetti
Messages: 7
Registered: July 2006
Junior Member
Hi Scott,

The above query is giving error.

Please let me know if any other options

Thanks in advance,
Dhani
Re: how to add hours to date [message #185834 is a reply to message #185829] Thu, 03 August 2006 16:22 Go to previous message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
And how are we supposed to know WHICH ERROR did you get? Was it, perhaps, ORA-01821?

By the way, Scott's suggestion works fine on my Oracle 10g.
SQL> alter session set nls_date_format = 'dd.mm.yyyy. hh24:mi';

Session altered.

SQL> SELECT
  2    SYSDATE now,
  3    SYSDATE + 1/24 now_plus_1_hour,
  4    TO_DATE('03.08.2006. 23:20',
  5            'dd.mm.yyyy. hh24:mi') + 1/24 approx_now_plus_1_hour
  6  FROM dual;

NOW                  NOW_PLUS_1_HOUR   APPROX_NOW_PLUS_1
-------------------- ----------------- -----------------
03.08.2006. 23:21    04.08.2006. 00:21 04.08.2006. 00:20

SQL>
Previous Topic: how to print our name 5 times rowwise using dual table
Next Topic: Duplicate emails, but need to isolate column value
Goto Forum:
  


Current Time: Sun Dec 04 20:25:49 CST 2016

Total time taken to generate the page: 0.03925 seconds