Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-02-2009
Member
 
Join Date: Jan 2009
Posts: 55
Date, days in HTML

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.
Reply With Quote
  #2  
Old 09-02-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Date, days in HTML

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 >
Reply With Quote
  #3  
Old 09-02-2009
Member
 
Join Date: Jan 2009
Posts: 55
Re: Date, days in 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.
Reply With Quote
  #4  
Old 09-02-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Date, days in HTML

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 >
Reply With Quote
  #5  
Old 09-02-2009
Member
 
Join Date: Jan 2009
Posts: 55
Re: Date, days in HTML

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!
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Date, days in HTML"
Thread Thread Starter Forum Replies Last Post
Need a formula to calculate years/days/months among several date in Excel Kumar esan MS Office Support 2 16-02-2012 08:05 PM
Date field in HTML form Messenger Software Development 6 29-07-2010 10:30 AM
Date Script at HTML Chrisch Software Development 3 19-11-2009 08:21 AM
find period in days / hours excluding weekdays between two days? Segvoia Software Development 3 19-06-2009 11:17 AM
How to Display Date 30 Days From Today Gayan Software Development 1 19-12-2008 02:52 PM


All times are GMT +5.5. The time now is 08:56 PM.