How do I rate a small piece of code to a webpage. It must figure out how many days have elapsed from a certain date.
Date eg. 01.12.2008
When I go into the next example today 11.12.2008
the writing has gone 10 days.
Printable View
How do I rate a small piece of code to a webpage. It must figure out how many days have elapsed from a certain date.
Date eg. 01.12.2008
When I go into the next example today 11.12.2008
the writing has gone 10 days.
Here is one, that can be used,
Code:< !DOCTYPE HTML PUBLIC "- //W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
<html> <head> <title> Days ago < /title >
<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">
< ! -- Minus Auto Date -- >
< script type="text/javascript" >
< ! --
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;
Date.prototype.timeSince = function () (
var now = new Date ();
var d = new Date (this.getTime ());
var years = 0;
while (d.setFullYear (d.getFullYear () + 1) <now) (years + +);
d.setFullYear (d.getFullYear () - 1);
var months = 0;
while (d.setMonth (d.getMonth () + 1) <now) (months + +);
d.setMonth (d.getMonth () - 1);
var days = 0;
while (d.setDate (d.getDate () + 1) <now) (days + +);
d.setDate (d.getDate () - 1);
hours = Math.floor ((now - d) / Date.ONE_HOUR);
minutes = Math.floor ((now - d)% Date.ONE_HOUR / Date.ONE_MINUTE);
seconds = Math.floor ((now - d)% Date.ONE_MINUTE / Date.ONE_SECOND);
var a = new Array ();
if (years> 0) a.push ([years, years == 1? 'years':' years']. join ( ''));
if (month> 0) a.push ([months, months == 1? 'months':' months']. join ( ''));
if (days> 0) a.push ([days, days == 1? 'days':' days']. join ( ''));
if (hours> 0) a.push ([hours, hours == 1? 'hours':' hours']. join ( ''));
if (minutes> 0) a.push ([minutes, minutes == 1? 'minutes':' minutes']. join ( ''));
if (seconds> 0) a.push ([seconds, seconds == 1? 'seconds'' seconds']. join ( ''));
return a.join ( '');
)
// -->
< /script >
< /head >
<body>
< DIV Style="text-align:center" >
< table Border="0" BGCOLOR="#80FFFF" CELLSPACING="5" CELLPADDING="5" >
< tr Align="center" >
< TD >
< script type="text/javascript" >
< ! --
then = new Date ( 'Dec 1, 2008'); // here write date
document.write ( '<p> have gone <span id="timeSince">' then.timeSince (), '< /span > since 1 Decem 2008: < /p >');
if (document.getElementById) setInterval ( "document.getElementById ( 'time since'). firstChild.data = then.timeSince ()", Date.ONE_SECOND / 5);
// -- >
< /script >
< /TD >
< /TR >
< /TABLE > < /DIV >
< /body >
< /html >
Thank you very much.
I had probably expected something that just filled 4 to 5 lines but this may not be feasible.
The way I need it:
It should be in a excel sheet which I then save as HTML in a file.
More simply, it may not be enough!
Now you wrote it should be in an Ecxel sheet, it has probably REALLY nothing to do with HTML, so how you can get it to work I do not know.
Code:< script type="text/javascript" >
//Set the two dates
var days ago = new Date (2008, 11, 1) // months is 0-11 in JavaScript
today = new Date ()
//Get 1 day in milliseconds
was one_day = 1000 * 60 * 60 * 24
//Calculate difference btw the two dates, and convert two days
document.write (Math.ceil ((today.getTime () dagesiden.getTime ())/( one_day)) +
"Days since 1 December 2008!")
< /script >
Can I get you to create a html file and put out where you put the 2 lines into the body? I've tried but it wont work for me!