CoderZone.org

Category: >> Oracle PL/SQL >> FUNCTIONS: date/time Bookmark and Share

<< lastnext >>

Snippet Name: FUNCTIONS: date/time

Description: Function to determine the difference between times

Also see:
» Calculate days between any two dat...
» Write or update an htpasswd file i...
» Validate file extensions in upload...
» Easy date manipulation
» Get Unix Timestamp for midnight to...
» Get Easter Date for any year in Ja...
» Check if a date is in the past
» Date Picker Form in ASP
» Convert Unix time string to a date...
» Copy Files By Date Modified
» LDAP Timestamp Converter
» Time left In Weeks, Days, Hours, A...
» Validate A URL
» Check whether a date belongs to a ...
» Get Relative Dates and Times
» Convert UK Dates To mySQL Format D...
» Measure script run time
» Calculate the difference between t...
» FUNCTIONS: Deterministic
» FUNCTIONS: Nested Functions
» FUNCTIONS: IF statement
» FUNCTIONS: Sample functions
» FUNCTIONS: drop
» FUNCTIONS: Recompile
» FUNCTIONS: DEBUG mode
» FUNCTIONS: IN OUT parameter
» FUNCTIONS: with output parameters
» FUNCTIONS: with parameters
» FUNCTIONS: without parameters

Comment: (none)

Author: CoderZone
Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 13th, 2009

CREATE OR REPLACE FUNCTION 
time_diff(DATE_1 IN DATE, DATE_2 IN DATE)
RETURN NUMBER IS
 NDATE_1   NUMBER;
 NDATE_2   NUMBER;
 NSECOND_1 NUMBER(5, 0);
 NSECOND_2 NUMBER(5, 0);
BEGIN
  -- Get Julian date number from
  -- first date (DATE_1)
  NDATE_1 := TO_NUMBER(TO_CHAR(DATE_1, 'J'));
 
  -- Get Julian date number from
  -- second date (DATE_2)
  NDATE_2 := TO_NUMBER(TO_CHAR(DATE_2, 'J'));
 
  -- Get seconds since midnight
  -- from first date (DATE_1)
  NSECOND_1 := TO_NUMBER(TO_CHAR(DATE_1, 'SSSSS'));
 
  -- Get seconds since midnight
  -- from second date (DATE_2)
  NSECOND_2 := TO_NUMBER(TO_CHAR(DATE_2, 'SSSSS'));
 
  RETURN (((NDATE_2 - NDATE_1)*86400)+(NSECOND_2 - NSECOND_1));
END time_diff;
/
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 9