View Full Version : Count Up Script
gazza58
04-23-2014, 12:58 PM
Hello
I'm hoping someone can assist me. I'm looking for a Count Up Script which I can use on a New Ticker page which counts from the day the message was published (i.e. starts with "Today" when published, changes to "Yesterday" the next day "2 Days Ago", "1 Week Ago" etc.
Dynamic Drive has a Count up Script but has Minutes, hours and seconds which I don't require. Would this be suitable for what I'm looking for and if so how could I modify
Any advice appreciated
Beverleyh
04-23-2014, 01:40 PM
What exactly is a "news ticker" page?
And how are you recording the publication date? Is that something which is stored in a database? Of maybe a last modified timestamp of a news entry file? Or the pubDate from an RSS feed? Or a static variable saved/written on the page itself?
This type of thing is usually easier and more accurate being calculated on the server side, so PHP would probably be the way to go. Is your server setup to run PHP? Assuming it is, these functions should do what you ask http://css-tricks.com/snippets/php/time-ago-function/
If you need more help, please provide a link to your page and give more information about how news dates/entries are being stored.
vwphillips
04-24-2014, 12:00 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<span id="posted" ></span>
<script type="text/javascript">
/*<![CDATA[*/
function zxcDaysPosted(o){
var obj=document.getElementById(o.ID),p=o.Date,p=typeof(p)=='string'?p.split(/\D/):[],d,w;
if (obj&&isFinite(p[0])&&isFinite(p[1])&&isFinite(p[2])){
d=Math.floor((new Date()-new Date(p[0],p[1]-1,p[2]))/(1000*60*60*24));
w=Math.floor(d/7);
obj.innerHTML=w+' Weeks '+(d-(w*7))+' Days';
o.to=setTimeout(function(){ zxcDaysPosted(o); },60000);
}
}
zxcDaysPosted({ID:'posted',Date:'2014-04-22'});
/*]]>*/
</script>
</body>
</html>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.