0

My function looks like this:

$(document).ready(function(){
    var d = new Date(document.lastModified);
    //  document.getElementById("lastup").innerHTML = d;
        $("#lastup").html(d);
        // Create a version number based on the date
            var cy = new Date();
            var y = cy.getFullYear()-2015;  // ex: 2018 - 2015 = 3  third year of program
            var mo = d.getMonth()+1;        // ex: 2 = Feb
            var dy = d.getDate();           // ex: 12 = Date of month
            var v = 'v'+y+'.'+mo+'.'+dy;    // ex: v3 = third year of program
                $("#version2").html(v);     // ex: v3.2.12  
});

The goal being to create a version number based on the last time the page code was changed. You can see the year part is based on years the program has been in place. But the month and day take there values from 'd' which is the value of "new Date(document.lastModified)" put it all together and you get a version number. But in this case it gives me a new version number for every day, it does not hold the last modified data, it always increments based on the date. Somewhere I'm not seeing the obvious here. Why is it doing this?

Keith D Kaiser
  • 1,016
  • 2
  • 14
  • 31
  • 1
    I think you misunderstand what `document.lastModified` represents. It's discussing the document as presented in your browser, not when the source file changed. You're going to need some mechanism to know when that source file changed, since that information is not sent when the file is served. –  Apr 09 '18 at 18:35
  • See [this stackoverflow q/a](https://stackoverflow.com/questions/9895202/what-is-the-difference-between-window-screen-and-document-in-javascript) to better understand what `document` means here. –  Apr 09 '18 at 18:45

0 Answers0