How to delete rows if date is older than x days in google sheets?

Describe the issue/error/question

How do I delete rows in Google Sheet if the date is older than 14 days?

What is the error message (if any)?

Please share the workflow

example data in google sheet

PixivID	Sanity	xRestrict	Artist	Date	ImageURL
99477820	0	0	想影真心	2022-07-03T19:08:56+09:00	https://i.pximg.net/img-original/img/2022/07/03/19/08/56/99477820_p0.jpg
99477725	4	0	墨郎	2022-07-03T19:04:50+09:00	
99477721	2	0	色紙	2022-07-03T19:04:44+09:00	
99477690	2	0	壱珂	2022-07-03T19:03:20+09:00	https://i.pximg.net/img-original/img/2022/07/03/19/03/20/99477690_p0.jpg

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:**0.184.0
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process [own(default), main]:
  • **Running n8n via [Docker, npm, n8n.cloud, desktop app]:**npm

Hi @Ruriko this is quite tricky in n8n and I think Google Sheets might not be the best database if you need to delete rows automatically. You’d essentially need to get the index for each row and can then build something like below to do the job. I am using the $position expression here to get the index:

This assumes your data starts in the second row like so:

If not you’d need to adjust the “Start Index” expression of the Delete row node in the above example accordingly.

It’s also important to only run this for a single row only (that’s what the Keep 1 node does in the example) as after each run the ID of each row would change, so this example would need to be executed multiple times.

If you don’t necessarily require Google Sheets, you could for example take a look at a database like Baserow instead. Fetching rows from Baserow gives you a unique ID for reach row which will make the deletion of data much easier (it also allows searching for data older than 14 days without having to use the IF node):

Other database would offer similar features as well.