Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1853
  • Last Modified:

googledoc spreadsheet last modified date

I am writing a script in a google doc spreadsheet that needs to check the last modified date of another google doc spreadsheet. How can I retrieve the last modified date of a google doc spreadsheet if I know its URL or key already?
0
reggieperrin
Asked:
reggieperrin
  • 3
  • 2
1 Solution
 
torvirCommented:
I tried it and got it to work with this script. The first line "var thisSheet..." and the last line are used only to be able to print the date in the present spreadsheet cell A1.
The file I am checking change date of is the file named "fileToCheckChangeDateUpon" which is a dummy file I created.

function dateOfTestfile() {
  var thisSheet = SpreadsheetApp.getActiveSheet();
  var files = DocsList.getFiles();
  var otherFileChangeDate = "Didn't find it";
  for (var n = 0; n < files.length; n++) {
    if (files[n].getName() == "fileToCheckChangeDateUpon") {
      otherFileChangeDate = files[n].getLastUpdated();
      break;
    }
  }
  thisSheet.getRange(1, 1).setValue(otherFileChangeDate);
}
0
 
reggieperrinAuthor Commented:
You rock! I tried your solution and it worked! However it is taking too long to go through all my files. How would I get it to only add jobs that start with "Job" into the files[n] array, before it starts searching through them?
0
 
torvirCommented:
If you know the file-ID you could use this syntax:
var file = DocsList.getFileById("t314159");

The script then becomes:

function dateOfTestfile() {
  var thisSheet = SpreadsheetApp.getActiveSheet();
  var file = DocsList.getFileById("t314159");
  var otherFileChangeDate = file.getLastUpdated();
  thisSheet.getRange(1, 1).setValue(otherFileChangeDate);
}
0
 
torvirCommented:
The ID is the string in the URL of the document between "key=" and "&"
0
 
reggieperrinAuthor Commented:
Fantastic solution! Thank you so much!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now