Q

Adding time using PL/SQL

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;

This was last published in March 2004

Dig Deeper on Using Oracle PL-SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close