Home > Ask the Oracle Database / Applications Experts > Questions & Answers > Adding time using PL/SQL
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Adding time using PL/SQL

Azim Fahmi EXPERT RESPONSE FROM: Azim Fahmi

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 16 March 2004
How can I add time to time using PL/SQL?

>
If your time is stored in a table in a column of DATE data type, you can do the following:

For example, say you want to add 1 hour and 30 minutes to your new time. You can do the following:

1 hour and 30 minutes is equal to 3600 + 1800 = 5400 seconds.

DECLARE

my_date_var DATE := null;
time_to_add  NUMBER := 5400 ; --  Between 0 and 86399 and whatever value you 
--  need to add
BEGIN
   
 SELECT DATE_FIELD
              INTO my_date_var
 FROM my_time_table
        WHERE MY_ID = ;

-- Set your values for time_to_add

IF time_to_add is between 0 and 86399 THEN
My_date_var := to_date(to_char(my_date_var, 'SSSSS') + time_to_add, 'SSSSS')
END IF;
...

-- UPDATE my_time_table or whatever business logic you need to process
...

END;


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts