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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fake a percentage depending on the time of day

Status
Not open for further replies.

a55m0nk

Programmer
Dec 23, 2003
4
GB
Hi all.

How could I go about creating a percentage that is created from the time of the day. So, for example at 20:00 it will be 90%, 21:00 will be 86% etc. Could it be done with Ifs:
If 21:00 < time < 21:59 then
percentage = 96

Any help would be greatly appreciated

a55m0nk
 
You could do that like so:
Code:
<script>
<!--
obj = new Date();
hour = obj.getHours();

if (hour == 21) {
	pct = 86;
} else {
	alert(hour);
}
//-->
</script>
But it would be better not to go through and define the percentage for each hour. Something like this would be nice:
Code:
<script>
<!--
obj = new Date();
hour = obj.getHours();
pct = Math.round(hour * 4.285);
alert(pct);
//-->
</script>
 
Thankyou for the quick reply, and the answer provided does the job better than i expected :p

thanks
a55m0nk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top