How to test creation of new sheet at the end of the month?

36 views
Skip to first unread message

William Lucid

unread,
Jul 8, 2023, 1:20:51 PM7/8/23
to Google Apps Script Community
I have a Google Script that logs web server data every 15 minutes.  Created script to log data monthly; then at the end of the month start a new sheet and continue logging.  This should continue year after year.
Learning scripting as I code with Google's Bard assisting.

Is there a way to check if the script will actually create a new sheet at the end of the month?

Gist of Google Script to log data

BME280 Logging --live view

William

Jon Couch

unread,
Jul 8, 2023, 2:11:34 PM7/8/23
to google-apps-sc...@googlegroups.com
William, I would have to work on the code a little bit to know the exact steps but here's the idea. 

1) Every time you log a reading start by checking the month of the previous timestamp and comparing it to the month of your new Date()
2) If the month of the new timestamp is not equal to the previous timestamp create a new sheet 
3) Save the timestamp in the appropriate sheet
4) To test it, edit the last timestamp to make it last month and run your function

Bard can probably get you close on the code for the comparison. I hope that helps, Jon


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2bf53c02-202e-4f64-b38e-3001c5ae4b6cn%40googlegroups.com.

William Lucid

unread,
Jul 11, 2023, 12:27:11 AM7/11/23
to Google Apps Script Community
Made the following changes to test creating the next months sheet:

now = endOfMonth; /* Added just above function getMonthNames */

function getMonthNames() {
  var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  //var monthName = months[new Date().getMonth()];
var monthName = months[
7]; /* next Month */
return monthName;
}

William

William Lucid

unread,
Jul 11, 2023, 12:33:00 AM7/11/23
to Google Apps Script Community
Thanks to Mr. Cooper on "Stack Overflow" for his answer about setting now equal to endOfMonth.

William

Guadalupe Rosiles

unread,
Jul 11, 2023, 1:21:29 AM7/11/23
to google-apps-sc...@googlegroups.com
--
Reply all
Reply to author
Forward
0 new messages