Click to See Complete Forum and Search --> : help: calculate elapsed time...
MyFirstJava
12-17-2003, 10:02 PM
Hi all,
Hope this is the right forum so here goes:
I'm a newbie and want to count the elapsed time between two dates using JS; one date stored in the access database and the other date is the today's date. So it's
todays_date - date_in_DB = elapsed time
I'm not sure how to call the date from Access into the JS and calculate the elapsed time. Not only that, the elapsed time must be running (not static). :confused:
I hope you guys can tell me how I can solve this problem. Better yet, I'd appreciate it very much if anyone can write down and show me the whole code (if it can be done that is)! BTW if I haven't explained clearly please tell me.
-mz s-
Well, javascript is client-side language, or your problem is deffinitely a server-side problem. So, as far as I know, I think you have 2 solutions
1. server-side only. Use a server-side application (php, asp, etc.) to compare current time with a value stored in a database and to generate a HTML page with the two values
2. server-side & client-side. Use a server-side app to generate a HTML page with the value stored in data base. Build a simple javascript code to return the curent time. Compare the two values.
NOTE... I don't know to much about that, but there must be a way to buid a server-type data base from an ACCES and than manipulate it with a server-side application language.
MyFirstJava
12-18-2003, 06:45 PM
I've got the code how to calculate elapsed time between a fixed date and today's date. All I need is to change this fixed date to the date from the database. How do I call it into JS? Do I need to write a code in ASP and call it into JS function? Can it be done? Are there any better suggestions? I'm not good at JS so sorry if I sound so ignorant.
BTW thanks for the suggestions Kor. Eventhough I'm still in the dark, at least you tried to help :)
You have to create a .JS file using a server side application (ASP if you said you know how) which can extract a value from a database. That .JS file (let's say basetime.js), will content that base time value, let's say baseValue:
var baseValue = here_is_the_value.
Now, in you HTML code insert in HEAD
<script language="JavaScript" src="basetime.js"></script>
write you javascript code you said you have and compare the current time with that value baseValue.
MyFirstJava
12-23-2003, 02:26 AM
Hi again,
I'm afraid I'm hopeless at this. Still in the dark. :( This is the script I found on the net which counts up from a fixed date (2000,11,17) to day's date. How can I change this so that it can call the date(s) from access and calculate the difference? Do I need to declare a function in VB at the top of the script and call it into the JS below? Is that possible? Or can this script be used at all? I really don't know what to do :(
<script language="JavaScript1.2">
function setcountup(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}
setcountup(2003,11,17)
var displaymessage="days have passed"
var countupwidth='95%'
var countupheight='20px' //applicable only in NS4
var countupbgcolor='lightyellow'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
function start_countup(){
if (document.layers)
document.countupnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
countup()
}
if (document.all||document.getElementById)
document.write('<span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"></span>')
window.onload=start_countup
function countup(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
paststring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(todaystring)-Date.parse(paststring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if (document.layers){
document.countupnsmain.document.countupnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+displaymessage+closetags)
document.countupnsmain.document.countupnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+displaymessage+closetags
setTimeout("countup()",1000)
}
</script>
<ilayer id="countupnsmain" width=&{countupwidth}; height=&{countupheight}; bgColor=&{countupbgcolor}; visibility=hide><layer id="countupnssub" width=&{countupwidth}; height=&{countupheight}; left=0 top=0></layer></ilayer>