Results 1 to 5 of 5

Thread: Date, days in HTML

  1. #1
    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.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    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 >

  3. #3
    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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 >

  5. #5
    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!

Similar Threads

  1. Replies: 2
    Last Post: 16-02-2012, 08:05 PM
  2. Date field in HTML form
    By Messenger in forum Software Development
    Replies: 6
    Last Post: 29-07-2010, 10:30 AM
  3. Date Script at HTML
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 08:21 AM
  4. find period in days / hours excluding weekdays between two days?
    By Segvoia in forum Software Development
    Replies: 3
    Last Post: 19-06-2009, 11:17 AM
  5. How to Display Date 30 Days From Today
    By Gayan in forum Software Development
    Replies: 1
    Last Post: 19-12-2008, 02:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,512,214.73486 seconds with 16 queries