i want my server time and date to be set as new date
i have tried this:
dateNow = new Date("<%=now()%>");
but this is not working
how can i do this?
here is the code that give me the problem…
it is just get stack on the time diff and doesn’t countdown
<script type="text/javascript">
dateFuture = new Date(<%=year(privatesellstartdate)%>,<%=month(privatesellstartdate)-1%>,<%=day(privatesellstartdate)%>,<%=hour(privatesellstarttime)%>,<%=minute(privatesellstarttime)%>,00);
function GetCount(){
dateNow = new Date(<%=year(date())%>,<%=month(date())-1%>,<%=day(date())%>,<%=hour(time())%>,<%=minute(time())%>,00); //grab current date
amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;
// time is already past
if(amount < 0){
document.getElementById('countbox').innerHTML="Now!";
}
// date is still good
else{
days=0;hours=0;mins=0;secs=0;out="";
amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
days=Math.floor(amount/86400);//days
amount=amount%86400;
hours=Math.floor(amount/3600);//hours
amount=amount%3600;
mins=Math.floor(amount/60);//minutes
amount=amount%60;
secs=Math.floor(amount);//seconds
if(days != 0){out += days +":";}
if(days != 0 || hours != 0){out += hours +":";}
if(days != 0 || hours != 0 || mins != 0){out += mins +":";}
out += ((secs>=10)?secs:"0"+secs) ;
document.getElementById('countbox').innerHTML=out;
setTimeout("GetCount()", 1000);
}
}
window.onload=GetCount;//call when everything has loaded
</script>
VBScript’s
Nowreturns the date and the time like:JavaScript’s Date() constructor doesn’t like that particular format. Instantiating a JavaScript Date with time from a string requires the time to be in 24h format. It looks like you’re trying to cobble it together correctly in the code you pasted though. Not sure why that isn’t working.
My question is why do the date comparison on the client-side at all? VBScript’s DateDiff would take care of this for you on the server-side: