Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Time???

Status
Not open for further replies.

zishan876

Programmer
Mar 19, 2007
61
US
Hi:
I have the following:
Code:
<html>
<head>
<script type="text/javascript" language="javascript" src="/js/functions.js"></script> 
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script>
<script type="text/javascript"> 
function initpage()
{

var d = "{!Delivery_Time__c.Actual_Arrival_Time__c}";
var e = "{!Dispatch_Schedule__c.Arrival_Time__c}";

var g=d.getTime()-e.getTime();

document.getElementById('div_tag').innerHTML = g ;
}
</script>
</head>
<body bgcolor="#F3F3EC" onload="initpage()";> 
<font size="2" face="Verdana">
<div id="div_tag">Loading...</div></font>
</body>
</html>
d&e value has the date in it.. so I thought getTime() would separate it and calculate the time difference...
d value is 3/14/2008 3:15 AM
e value is 3/14/2008 2:00 AM
its an 1:15 difference which I want g to say...
Plz Help???
 
You're treating "getTime" as a method on a String object - which it is not. Only the Date object has a getTime method, so you'd need to convert your Strings to Dates first.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
ok so if I do this it writes out 4500000???
Code:
<html>
<head>
<script type="text/javascript" language="javascript" src="/js/functions.js"></script> 
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script>
<script type="text/javascript"> 
function initpage()
{
//Set the two dates
var millennium =new Date("{!Delivery_Time__c.Actual_Arrival_Time__c}") ;
today=new Date("{!Dispatch_Schedule__c.Arrival_Time__c}");

document.write(millennium.getTime()-today.getTime());
}
</script>

</head>
<body bgcolor="#F3F3EC" onload="initpage()";> 
[\code]
does anyone know how to convert it so it states 1:15
Thanks
 
ok so if I do this it writes out 4500000???

What do you expect it to write out? The getTime method converts a date to milliseconds, so you're essentially calculating the millisecond difference between the 2 dates. 4500000 milliseconds is the same as 1.25 hours, which doesn't seem like a lot of time to me... [ponder]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top