codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  time difference  diego at 08:25 on Friday, November 21, 2003
 

<script language=javascript>
<!--
function timeDiff(strTime1, strTime2)
{
var date1= new Date('1/1/03 ' + strTime1);
var date2= new Date('1/1/03 ' + strTime2);

var mins1= (date1.getHours() * 60) + date1.getMinutes();
var mins2= (date2.getHours() * 60) + date2.getMinutes();
var diff;

if ( mins1 <= (12*60) && mins2 >= (13*60) )
{
diff= (mins2 - (mins1 + 60)) / 60;
}
else
{
diff= (mins2 - mins1) / 60 - 1;
}
return UntoNdp(diff,2);
}

function UntoNdp(X, N)
{
var p = Number('1e'+N), S = new String(Math.round(X*p)/p)
if (S.indexOf('e') == -1 ) {
while ( (p = S.indexOf('.')) == -1 ) { S += '.' }
while ( S.length <= p+N ) { S += '0' } }
return S
}
//-->
</script>


<input type=text name="date1" size="15">

<input name="timein" type="text">



<input type=text name="date2" size="15">

<input name="timeout1" type="text">



<input type="text" size="10" name="txtTime3">
<input type="button" value="click to view the no. of hours spent" onclick="this.form.txtTime3.value=(timeDiff(this.form.timein.value,this.form.timeout1.value));">


my existing script shows the difference between two times,whenever the user clicks the button
it displays on the textbox the difference of the two given times.

My problem is the dates if the value of two date like

11/20/2003 5:48 PM
11/21/2003 2:00 AM

to get the difference of two times the two dates should also be considered and i am using
Function timeDiff.

pls. help!

thanks









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  New LucidWorks certified distribution for Solr
•  Re: submit button on html form
•  Re: FREE TV on your PC!
•  Re: How to edit a PCL file
•  Re: How to open a pop up without Titlebar?
•  Re: Testing if object exists in IE
•  Re: windows service - web service - com
•  Re: Save up to 80% on SSL Certificates, RapidSSL Certificate @ $ 11.00/yr.
•  Re: Using ASP to write RTF


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010