Search This Blog

Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Friday, February 25, 2022

Oracle / PLSQL: Retrieve the total elapsed time in minutes between two dates

 

Oracle / PLSQL: Retrieve the total elapsed time in minutes between two dates

Question: In Oracle, how can I retrieve the total elapsed time in minutes between two dates?

Answer: To retrieve the total elapsed time in minutes, you can execute the following SQL:

select (endingDateTime - startingDateTime) * 1440
from table_name;

Since taking the difference between two dates in Oracle returns the difference in fractional days, you need to multiply the result by 1440 to translate your result into elapsed minutes.

24 * 60 = 1440

24 hours in a day * 60 minutes in an hour

Oracle / PLSQL: Insert a date/time value into an Oracle table

 

Oracle / PLSQL: Insert a date/time value into an Oracle table

Question: I have a date field in an Oracle table and I want to insert a new record. I'm trying to insert a date with a time component into this field, but I'm having some problems.

How can I insert this value into the table.

For example, the value is '3-may-03 21:02:44'

Answer: To insert a date/time value into the Oracle table, you'll need to use the TO_DATE function. The TO_DATE function allows you to define the format of the date/time value.

For example, we could insert the '3-may-03 21:02:44' value as follows:

insert into table_name
(date_field)
values
(TO_DATE('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss'));

Learn more about the TO_DATE function.

PL/SQL - Collections

A collection is an ordered group of elements having the same data type. Each element is identified by a unique subscript that represents its...