Skip to main content link. Accesskey S
  • Help
  • HCL Logo
  • HCL Notes and Domino Application Development wiki
  • THIS WIKI IS READ-ONLY. Individual names altered for privacy purposes.
  • HCL Forums and Blogs
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • API Documentation
Search
Community Articles > Programming > JavaScript > Various Time Differences in JavaScript
  • Share Show Menu▼
  • Subscribe Show Menu▼

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 ~Dana Xankroikle | Edited by ~Dana Xankroikle on March 24, 2010 | Version 17
  • Actions Show Menu▼
expanded Abstract
collapsed Abstract
No abstract provided.
Tags: datetime
ShowTable of Contents
HideTable of Contents
  • 1 Various Time Differences
    • 1.1 Usage

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); 
Visit keithstric.comexternal link for other Lotus Notes/Domino/XPage articles 


  • Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (17)
collapsed Versions (17)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (17)Mar 24, 2010, 3:42:35 PM~Dana Xankroikle  
16Mar 24, 2010, 3:13:50 PM~Mary Reluveroden  
15Mar 4, 2010, 5:08:56 PM~Mary Reluveroden  
14Mar 4, 2010, 5:08:07 PM~Mary Reluveroden  
13Mar 4, 2010, 5:07:45 PM~Mary Reluveroden  
12Mar 4, 2010, 5:06:35 PM~Mary Reluveroden  
11Mar 4, 2010, 5:04:01 PM~Mary Reluveroden  
10Mar 4, 2010, 5:02:29 PM~Mary Reluveroden  
9Mar 4, 2010, 5:01:42 PM~Mary Reluveroden  
8Mar 4, 2010, 5:00:25 PM~Mary Reluveroden  
7Mar 4, 2010, 4:59:32 PM~Mary Reluveroden  
6Mar 4, 2010, 4:58:28 PM~Mary Reluveroden  
5Mar 4, 2010, 4:57:40 PM~Mary Reluveroden  
4Mar 4, 2010, 4:53:34 PM~Mary Reluveroden  
3Mar 4, 2010, 4:53:08 PM~Mary Reluveroden  
2Mar 4, 2010, 4:51:12 PM~Mary Reluveroden  
1Mar 4, 2010, 4:49:12 PM~Mary Reluveroden  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedAbout
  • HCL Software
  • HCL Digital Solutions community
  • HCL Software support
  • BlogsDigital Solutions blog
  • Community LinkHCL Software forums and blogs
  • About HCL
  • Privacy
  • Accessibility