Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 JavaScript: Calculate time difference between two dates Jump to:  
Category: >> JavaScript >> Calculate time difference between two dates Bookmark and Share

<< lastnext >>

Snippet Name: Calculate time difference between two dates

Description: Calculates the time difference between two dates.

Also see:
» Get Relative Dates and Times
» Convert UK Dates To mySQL Format Dates
» Calculate the difference between two t...
» %TYPE vs %ROWTYPE - What's the differe...
» Dates: Oddball Stuff
» Date/Time Calculations: Get seconds be...
» Date Functions: Add and Subtract from ...
» Add and Subtract dates
» Select or match a range of dates
» Calculate time difference between two ...
» Count days between dates
» Find days between dates #1

Comment: (none)

Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: February 27th, 2009

FUNCTION timeDifference(laterdate,earlierdate) {
    VAR difference = laterdate.getTime() - earlierdate.getTime();
 
    VAR daysDifference = Math.floor(difference/1000/60/60/24);
    difference -= daysDifference*1000*60*60*24
 
    VAR hoursDifference = Math.floor(difference/1000/60/60);
    difference -= hoursDifference*1000*60*60
 
    VAR minutesDifference = Math.floor(difference/1000/60);
    difference -= minutesDifference*1000*60
 
    VAR secondsDifference = Math.floor(difference/1000);
 
 document.WRITE('difference = ' + daysDifference + ' day/s ' + hoursDifference + ' hour/s ' + minutesDifference + ' minute/s ' + secondsDifference + ' second/s ');
 
VAR laterdate = NEW Date(2000,0,1);     // 1st January 2000
VAR earlierdate = NEW Date(1998,2,13);  // 13th March 1998
 
timeDifference(laterdate,earlierdate);
}


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 164 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?