Get date of file - What am I doing wrong?

I set up the following code to check how many days have elapsed since a file has been uploaded:

function fileModified(url){  // returns modification date of a file
        var Oxml= new window.XMLHttpRequest();"HEAD", url, false);
        if(Oxml.status== 200){
            var lastmod = Oxml.getResponseHeader('Last-Modified');
            return lastmod;
        else return null;
        return null;
// Calculate how many days since file was modified till now
modified = fileModified(location.href);
var now = new Date();
var msecsPerDay = 1000 * 60 * 60 * 24;
var msecsDiff = now.getTime() - modified.getTime();
var diff= msecsDiff / msecsPerDay ;

alert("Days since file was uploaded= "+diff);

My problem is that modified.getTime() doesn’t work. Apparently the result of Oxml.getResponseHeader(‘Last-Modified’) is a string, such as Sun, 21 Nov 2010 21:17:49 GMT.

I tried and tried - but couldn’t get to make a proper date out of this.

The final result that I need is the time since the file was uploaded.


Turn the string in to a date, then use one of the Date methods to retrieve the time.

var modifiedDate = new Date(modified);
var modifiedTime = modifiedDate.getTime();

Worked like a charm.