1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GASで毎月の決められた日に行うイベントを登録する

Posted at

曜日や稼働日かどうかに関係なく、毎月決められた日にちに行うイベント作成を簡単に行います。
googleカレンダーにはこのような繰り返しでのイベント登録がないので、また自作しました。
このスクリプトは実行すると、1年単位でイベント登録(最大12イベント)されます。

ソースコード

const CALENDAR_ID = '************'; //カレンダーID

function createSpecifiedDateEvent() {
  const calendar = CalendarApp.getCalendarById(CALENDAR_ID); // 検索元カレンダー
  
  let dateNum = 31; // 毎月イベントを登録したい日にち(1~31)

  let createEventYear = 2020; // イベント作成する年

  let createEventStartTime = 0; // イベントの開始時刻(24H表記)
  let createEventEndTime = 1; // イベントの終了時刻(24H表記)
  let createEventName = "先月の振り返り"; // イベントの名称
  
  // 12ヶ月分繰り返す
  for(let i = 1; i < 12+1; i++){
    
    // もし登録したい日にちがその月に存在すれば
    // (dateNumで31を指定した場合、2/31や4/31は存在しない、存在しない場合は登録をさせない)
    if(dateNum <= new Date(createEventYear, i, 0).getDate()){
    
      // 毎月の指定日にイベント作成
      calendar.createEvent(createEventName,
                           new Date(""+createEventYear+"/"+i+"/"+dateNum+" "+createEventStartTime+":00:00"),
                           new Date(""+createEventYear+"/"+i+"/"+dateNum+" "+createEventEndTime+":00:00"));
    }
    
  }
}

参考にさせて頂いたURL

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?