rusty "Razorblade" coslett
stainless musings

1/24 + 1/24 = 2 hours PL what?

Thursday, August 28, 2008 5:45 PM

I am really, really new to PL/SQL having spent time on DB2/400 and MSSQL most of my career. I needed to manipulate time in Oracle and tried to apply existing knowledge with mixed results.

Craziness like having to select from table 'dual' instead of nixing the 'from' keyword like in T-SQL. Weird.

This site has helped a lot due its simple examples to help build my confidence. So anyway on to the title of the post... (sorry for the alignment of the code, first time pasting from Toad)

I am really curious why the creators of Oracle chose this particular syntax for manipulating time. It is not bad, just unexpected.

PL/SQL

select to_char(sysdate,'HH24') as "curhour",to_char(sysdate+1/24+1/24,'HH24') as "Twoplus" from dual


T/SQL

select datepart(hh,getdate()) as 'curhour', datepart(hh,dateadd(hh,2,getdate()))


It would be great if someone has a good site explaining the reasoning behind 1/24. If I missed something somewhere, please let me know a better way!

rusty



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: 1/24 + 1/24 = 2 hours PL what?

In Oracle, dates include a fractional portion. There are 24 hours in a day, so if you want to add an hour you simply add 1/24. If you want to add 5 hours, add 5/24. If you want to add a full day
simply add 1 (24/24).

By the way, you can round the date to the nearest hour if you like

select round(sysdate,'HH24') "rounded",
trunc(sysdate,'HH24') "truncated"
from dual;
8/29/2008 2:16 PM | Will

Post a comment