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

いわゆる、毎月10,20,30日のゼロのつく日のイベント作成を簡単に行います。
googleカレンダーにはこのような繰り返しでのイベント登録がないので、自作しました。

ソースコード

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

function createSaleEvent() {
  const calendar = CalendarApp.getCalendarById(CALENDAR_ID); // 検索元カレンダー
  
  let dateNum = 0; // 指定したい下1桁の日にち(例:0であれば、10,20,30の日にイベント作成)

  let createEventYear = 2020; // イベント作成する年
  let createEventMonth = 1; // イベント作成する月
  let createEventDay = new Date(createEventYear, createEventMonth, 0).getDate(); // イベント作成する月の日数
  let createEventStartTime = 12; // イベントの開始時刻(24H表記)
  let createEventEndTime = 13; // イベントの終了時刻(24H表記)
  let createEventName = "セールの日"; // イベントの名称
  
  for(let i = 1; i < createEventDay+1; i++){
  
    // 日にちを10で割った余りが指定した下1桁の日にちとイコールであれば、イベント作成
    if(i%10 == dateNum){
      calendar.createEvent(createEventName,
                           new Date(""+createEventYear+"/"+createEventMonth+"/"+i+" "+createEventStartTime+":00:00"),
                           new Date(""+createEventYear+"/"+createEventMonth+"/"+i+" "+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?