I have this bit of code that aside from the attempt related to modifiedDate
, it works fine.
const MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
const now = new Date();
const yesterday = new Date(now.getTime() - MILLIS_PER_DAY);
function extractStudentIDsAndSectionToSheets(){
const ss = SpreadsheetApp.getActiveSpreadsheet()
const folder = DriveApp.getFolderById(FOLDER_ID);
const files = DriveApp.searchFiles('title contains "stuff" and mimeType = "application/pdf" and modifiedDate > "' yesterday '" and trashed=false');
let allIDsAndCRNs = []
//Iterate through each folder
while(files.hasNext()){
let file = files.next();
let fileID = file.getId();
(...)
The aim is to filter the files that are newer than yesterday (24h) but I'm having trouble adding that condition. It works fine If I use specific data, but I want to add a daily trigger to the script, so that's why it shouldn't be a static data.
How can I do this? Thank you in advance
CodePudding user response:
You need to format the date to yyyy-mm-dd see doc
This how to change Date format see doc
Try this:
const MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
const now = new Date();
const yesterday = new Date(now.getTime() - MILLIS_PER_DAY);
const formatedDate = Utilities.formatDate(yesterday, "GMT", 'yyyy-MM-dd');
function extractStudentIDsAndSectionToSheets() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const folder = DriveApp.getFolderById(FOLDER_ID);
const files = DriveApp.searchFiles('title contains "stuff" and mimeType = "application/pdf" and modifiedDate > "' formatedDate '" and trashed=false');
let allIDsAndCRNs = []
//Iterate through each folder
while (files.hasNext()) {
let file = files.next();
let fileID = file.getId();
(...)