last modified with days since last change

i am looking for a javascript that displays when the page was last modified (day name, month, date format) as well as the number of days since it was last changed (2 days ago). so it would read something like:

last modified on mon, nov 29, 0 days ago.

i have found this one, it seems fine, but when i put it on my server it said -1 day when it should have said 0 days. Can someone please help? is there an easy fix, or another script? i want it to just reference the date that i modify it - not anything on the server.

<script language=JavaScript>
<!-- Hide
// Array of day names
var dayNames = new

Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
// Array of month names
var monthNames = new

Array("January","February","March","April","May","June","July","August","September","October","November","December");

today = new Date()
lastmod = new Date(document.lastModified)
diffdays = Math.floor( (today.getTime()-
lastmod.getTime())/(24*60*60*1000) )
var then = new Date(document.lastModified);
document.writeln("Showroom last updated on "+
dayNames[then.getDay()] + ", " + monthNames[then.getMonth()] + " " + then.getDate() + " | " + diffdays + " days ago")
// Unhide -->
</script>
chuckp27Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

archrajanCommented:

function writeDateModified (time) {

  var days = new Array;                        // Array to hold day names
  var months = new Array;                      // Array to hold up month names

  // Load up day names
  days[0] = "Sunday";
  days[1] = "Monday";
  days[2] = "Tuesday";
  days[3] = "Wednesday";
  days[4] = "Thursday";
  days[5] = "Friday";
  days[6] = "Saturday";

  // Load up month names
  months[0] = "January";
  months[1] = "February";
  months[2] = "March";
  months[3] = "April";
  months[4] = "May";
  months[5] = "June";
  months[6] = "July";
  months[7] = "August";
  months[8] = "September";
  months[9] = "October";
  months[10] = "November";
  months[11] = "December";

  // Assign date variables with document.lastModified
  var modDate = new Date(Date.parse(document.lastModified));
 
  // If we have a valid date reformat it.
  if (modDate != 0) {
 
    // Set up day variable to hold the name of the day
    var day = days[modDate.getDay()];
   
    // ndate variable holds day of month
    var ndate = modDate.getDate();
   
    // Set up month variable to hold the name of the month
    var month = months[modDate.getMonth()];
   
    // Get the year and if it is less than 1000 add 1900 to it.
    var year = modDate.getYear();
    if (year < 1000) year = year + 1900;
   
    // Load up the time variables if required
    if (time) {
      var hour = modDate.getHours().toString();
      if (hour.length == 1) hour = "0" + hour;
      var minute = modDate.getMinutes().toString();
      if (minute.length == 1) minute = "0" + minute;
      var second = modDate.getSeconds().toString();
      if (second.length == 1) second = "0" + second;
    }
   
    // Display date and time document was last updated.
    document.write(day + " " + ndate + " " + month + " " + year+ "  ");
    if (time) {
      document.write(hour + ":" + minute + ":" + second);
    }
  }
}
0
archrajanCommented:
date difference
function dateDiff(dateform) {
date1 = new Date();
date2 = new Date();
diff  = new Date();

if (isValidDate(dateform.firstdate.value) && isValidTime(dateform.firsttime.value)) { // Validates first date
date1temp = new Date(dateform.firstdate.value + " " + dateform.firsttime.value);
date1.setTime(date1temp.getTime());
}
else return false; // otherwise exits

if (isValidDate(dateform.seconddate.value) && isValidTime(dateform.secondtime.value)) { // Validates second date
date2temp = new Date(dateform.seconddate.value + " " + dateform.secondtime.value);
date2.setTime(date2temp.getTime());
}
else return false; // otherwise exits

// sets difference date to difference of first date and second date

diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

timediff = diff.getTime();

weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

days = Math.floor(timediff / (1000 * 60 * 60 * 24));
timediff -= days * (1000 * 60 * 60 * 24);

hours = Math.floor(timediff / (1000 * 60 * 60));
timediff -= hours * (1000 * 60 * 60);

mins = Math.floor(timediff / (1000 * 60));
timediff -= mins * (1000 * 60);

secs = Math.floor(timediff / 1000);
timediff -= secs * 1000;

dateform.difference.value = weeks + " weeks, " + days + " days, " + hours + " hours, " + mins + " minutes, and " + secs + " seconds";

return false; // form should never submit, returns false
}
0
archrajanCommented:
This gives all in one script...
function lastMod()
{
      var x = new Date (document.lastModified);
      Modif = new Date(x.toGMTString());
      Year = takeYear(Modif);
      Month = Modif.getMonth();
      Day = Modif.getDate();
      Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
      x = new Date();
      today = new Date(x.toGMTString());
      Year2 = takeYear(today);
      Month2 = today.getMonth();
      Day2 = today.getDate();
      now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
      daysago = now - Mod;
      if (daysago < 0) return '';
      unit = 'days';
      if (daysago > 730)
      {
            daysago = Math.floor(daysago/365);
            unit = 'years';
      }
      else if (daysago > 60)
      {
            daysago = Math.floor(daysago/30);
            unit = 'months';
      }
      else if (daysago > 14)
      {
            daysago = Math.floor(daysago/7);
            unit = 'weeks'
      }
      var towrite = 'Page last changed ';
      if (daysago == 0) towrite += 'today';
      else if (daysago == 1) towrite += 'yesterday';
      else towrite += daysago + ' ' + unit + ' ago';
      return towrite;
}


function takeYear(theDate)
{
      x = theDate.getYear();
      var y = x % 100;
      y += (y < 38) ? 2000 : 1900;
      return y;
}

and finally at the place where it should be written

document.write(lastMod())

0
archrajanCommented:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<script>
function lastMod()
{
      var x = new Date (document.lastModified);
      Modif = new Date(x.toGMTString());
      Year = takeYear(Modif);
      Month = Modif.getMonth();
      Day = Modif.getDate();
      Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
      x = new Date();
      today = new Date(x.toGMTString());
      Year2 = takeYear(today);
      Month2 = today.getMonth();
      Day2 = today.getDate();
      now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
      daysago = now - Mod;
      if (daysago < 0) return '';
      unit = 'days';
      if (daysago > 730)
      {
            daysago = Math.floor(daysago/365);
            unit = 'years';
      }
      else if (daysago > 60)
      {
            daysago = Math.floor(daysago/30);
            unit = 'months';
      }
      else if (daysago > 14)
      {
            daysago = Math.floor(daysago/7);
            unit = 'weeks'
      }
      var towrite = 'Page last changed ';
      if (daysago == 0) towrite += 'today';
      else if (daysago == 1) towrite += 'yesterday';
      else towrite += daysago + ' ' + unit + ' ago';
      return towrite;
}


function takeYear(theDate)
{
      x = theDate.getYear();
      var y = x % 100;
      y += (y < 38) ? 2000 : 1900;
      return y;
}



document.write(lastMod())
</script>

</BODY>
</HTML>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chuckp27Author Commented:
thanks. even better than i hoped!!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.