When you are working as an Analyst, your main part of the job is to create reports with important KPI which help business to understand in detail about how their business is performing. Also performing automation or creating automated reports are one more task. While working and automating Google Spreadsheet, you have come across a situation where you want to get Spreadsheet creation and modification date. This task can be automated using the Google Apps Script (GAS).
Here in this post we will see how you can automatically update the Spreadsheet creation and last modification date in a cell using Google Apps Script.
Below is the Google Apps Script code which will get the Google Spreadsheet creation date along with the last modification date as well.
function GetDate() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var s = ss.getSheetByName('Sheet_name'); var dateCreated = DriveApp.getFileById('Google_Spreadsheet_ID').getDateCreated() s.getRange('B7').setValue(dateCreated); var lastUpdated = DriveApp.getFileById('Google_Spreadsheet_ID').getLastUpdated() s.getRange('B8').setValue(lastUpdated); };
Here in the above code, we are checking the current active spreadsheet and then getting the sheet name which we are looking for. Then we have created two variable datecreated and lastupdated, and using the spreadsheetID we are fetching the .getDateCreated() and .getLastUpdated() methods of the FILE class and finally putting the values in the “B7” and “B8” cells respectively.
To get more detailed knowledge about Google Apps Script, you can check the official website. Also if you want to explore more codes/posts related to Google Apps Script on our website, then you can find it here.
If you have any questions or if you need any help please get in touch with me using the comment section below.
Leave a Reply