Skip to main content link. Accesskey S
  • Help
  • IBM Logo
  • IBM Notes and Domino Application Development wiki
  • All Wikis
  • All Forums
  • THIS WIKI IS READ-ONLY. Learn more...
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
  • API Documentation
Search
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

Click to view profileKeith Strickland
Contribution Summary:
  • Articles authored: 4
  • Articles edited: 4
  • Comments Posted: 0

Recent articles by this author

The JSON RPC Service

Use the JSON RPC Service included in the Extension Library to communicate with the server from Client Side Javascript in an XPage

Using dojo.style to adjust the style of DOM Nodes

Have you ever wished you could set the style of an element programmatically, well using dojo.style now you can.

Get the browser window Height and Width

Get a browser window height and width These client side JavaScript functions will return the height and width of the browser window content area. This is useful when doing graphics operations with a javascript library like Dojo, Moo Tools, jQuery, etc. Window Height  The height of the ...

Various Time Differences in JavaScript

Various Time Differences Find the difference in 2 datetimes by day, hour, minutes and seconds.   Get the time difference between 2 dates in days  function timeDayDifference(endDate,startDate) {   var difference endDate.getTime() startDate.getTime();   difference ...
Community articleVarious Time Differences in JavaScript
Added by Keith Strickland | Edited by Keith Strickland on March 4, 2010 | Version 7
expanded Abstract
collapsed Abstract
No abstract provided.
Tags: datetime
ShowTable of Contents
HideTable of Contents
  • 1 Various Time Differences
  • 2 Various Time Differences
    • 2.1 Usage

Various Time Differences

 
 

Various Time Differences

 
Find the difference in 2 date/times by day, hour, minutes and seconds. 
 


 /**
  * Get the time difference between 2 dates in days
  */
 function timeDayDifference(endDate,startDate) {
 	var difference = endDate.getTime() - startDate.getTime();	
 	difference -= (Math.floor(difference/1000/60/60/24)*1000*60*60*24);
 	return difference;
 }
 /**
  * Get the time difference between 2 dates in hours
  */
 function timeHourDifference(endDate,startDate) {
 	var difference = endDate.getTime() - startDate.getTime();
 	difference -= (Math.floor(difference/1000/60/60)*1000*60*60);
 	return difference;
 }
 /**
  * Get the time difference between 2 dates in minutes
  */
 function timeMinuteDifference(endDate,startDate) {
 	var difference = endDate.getTime() - startDate.getTime();
 	difference -= (Math.floor(difference/1000/60)*1000*60);
 	return difference;
 }
 /**
  * Get the time difference between 2 dates in seconds
  */
 function timeSecondDifference(endDate,startDate) {
 	var difference = endDate.getTime() - startDate.getTime();
 	difference = Math.floor(difference/1000);
 	return difference;
 } 
 

Usage

 
 
 
var startDateTime = new Date(2010,5,10,8,0);
var endDateTime = new Date(2010,5,11,8,0); 
 
var dayDiff = timeDayDifference(endDateTime,startDateTime) ;
var hourDiff =  timeHourDifference(endDateTime,startDateTime);
var minDiff = timeMinuteDifference(endDateTime,startDateTime); 
var secDiff = timeSecondDifference(endDateTime,startDateTime); 
 
expanded Attachments (0)
collapsed Attachments (0)
expanded Versions (17)
collapsed Versions (17)
Version Comparison     
VersionDateChanged by              Summary of changes
17Mar 24, 2010, 11:42:35 AMKeith Strickland  
16Mar 24, 2010, 11:13:50 AMKeith Strickland  
15Mar 4, 2010, 12:08:56 PMKeith Strickland  
14Mar 4, 2010, 12:08:07 PMKeith Strickland  
13Mar 4, 2010, 12:07:45 PMKeith Strickland  
12Mar 4, 2010, 12:06:35 PMKeith Strickland  
11Mar 4, 2010, 12:04:01 PMKeith Strickland  
10Mar 4, 2010, 12:02:29 PMKeith Strickland  
9Mar 4, 2010, 12:01:42 PMKeith Strickland  
8Mar 4, 2010, 12:00:25 PMKeith Strickland  
This version (7)Mar 4, 2010, 11:59:32 AMKeith Strickland  
6Mar 4, 2010, 11:58:28 AMKeith Strickland  
5Mar 4, 2010, 11:57:40 AMKeith Strickland  
4Mar 4, 2010, 11:53:34 AMKeith Strickland  
3Mar 4, 2010, 11:53:08 AMKeith Strickland  
2Mar 4, 2010, 11:51:12 AMKeith Strickland  
1Mar 4, 2010, 11:49:12 AMKeith Strickland  
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • FacebookIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkThe Social Lounge
  • Wiki Help
  • Forgot user name/password
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use