Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2021年7月25日日曜日

現在日時から四半期の開始日と終了日を知りたい


今の日時を取得して、現在の四半期の開始日と終了日を知りたくて書いたコードです。



コード.gs
function myFunction() {
  const month = new Date().getMonth() + 1;// monthは0始まりなので+1
  const quater = judgeQuater(month);
  Logger.log([month, quater]);
}

/************************************
受け取った月からそのQuaterのStartDateと EndDateとQuaterを返す
************************************/
function judgeQuater(month) {
  switch(month) {
    case 7:
    case 8:
    case 9:
      return ["07-01", "09-30", "Q1"];
    case 10:
    case 11:
    case 12:
      return ["10-01", "12-31", "Q2"];
    case 1:
    case 2:
    case 3:
      return ["01-01", "03-31", "Q3"];
    case 4:
    case 5:
    case 6:
      return ["04-01", "06-30", "Q4"];
  }
}




ログ

Latest post

スプレッドシートの空白セルを直前の値で埋めたい

A列の空白セルに直前の値を入れたくて書いたコードです スプレッドシートに以下のようなBeforeの表があるとき (A列に空白セルがある) Before 1 A B 2 エリア 都市 3 東京 新宿 4 渋谷 5 池袋 6 神奈川 横浜 7 川崎 8 相模原 9 千葉 千葉 10 ...