ArcaneZorro
ArcaneZorro

Reputation: 3

How do I use a macro to name a sheet with yesterday's date?

Here's what I have now that doesn't work,

spreadsheet.getActiveSheet().setName(Today()-1);

I was wondering if I could just use 'Today() - 1' in cell A1 for example and pull the data from that. Any help would be greatly appreciated. Thanks!

Upvotes: 0

Views: 320

Answers (2)

Cooper
Cooper

Reputation: 64100

var today=new Date();
var yesterday=new Date(today.getFullYear(), today.getMonth(), today.getDate()-1);

Upvotes: 0

Krishna Vyas
Krishna Vyas

Reputation: 1028

To name a sheet with yesterday's date, Use a macro like this -

function myFunction() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var date = new Date()
  var ydate = Utilities.formatDate(new Date(date.getTime()-(24*3600*1000)), "GMT+1", "dd/MM/yyyy")
  spreadsheet.setName(ydate);
}

This is working perfecly.

Upvotes: 1

Related Questions