Home > Enterprise >  Using Google Apps Script to Move Data to New Sheet After Time Delay
Using Google Apps Script to Move Data to New Sheet After Time Delay

Time:12-24

I am attempting to write a script that will scan a spreadsheet where one column contains date data (Column C) and if 72 hours or more have passed, move the entire row of data to a new spreadsheet.

This is the format for the date data:

MM/DD/YYYY H:MM:SS

Example:

12/11/2022 9:21:19

This is an example of the google sheet where data enters:

SPREADSHEET 1 (Receives Incoming Data)

Name Date
Josh 2022-11-29 20:29:47
Samantha 2022-12-23 19:25:52

So based on this example, the script would move the entire second row to a new spreadsheet (since more than 72 hours have passed between the date and the current time):

SPREADSHEET 2

Name Date
Josh 2022-11-29 20:29:47

My goal is to have this script "listen" for any new rows added to the google spreadsheet and automatically move rows once 72 hours have passed.

I have tried building this with excel functions but get errors where the expected number of rows and actual rows are not equal.

I am very new with google app scripts but I used the following two posts to try and piece together code but can't get it to deploy:

enter image description here

This script checks the column B if the date is more than 3 days. Then moves the rows to another spreadsheet if it is. Otherwise it stays there.

However, there is no way for Google Apps Script to keep track of these dates since they can't hold these date values and only move them once they go past 72 hours.

What you can do is use a Time-driven trigger. This will run the script automatically according to what you setup.

  • By going to Triggers on the left panel
  • Add Trigger
  • Event Source: Time-driven. Then the type and interval will be up to you either by hour or minute, experiment which works best for you.
  • Related