実現したいこと
googleフォームからgoogleスプレッドシートへ自動転記
googleフォーム側のGASで編集用URLを追記したい
その際にレコードに誤りがないか確認するため日付の比較がしたいが、一見同じデータにみえる(というか同じのはず)のにうまく比較ができない
該当のソースコード
console.log(timestamp); console.log(sh_alldata.getRange(7, 1).getValue()); if(timestamp === sh_alldata.getRange(7, 1).getValue()){ console.log("1:timestamp ===sh_alldata.getRange(7, 1).getValue()"); } //データ型に変換 var test_date = new Date(sh_alldata.getRange(7, 1).getValue()); var t_date= new Date(timestamp); console.log(t_date); console.log(test_date); if(timestamp === test_date){ console.log("1:timestamp ===test_date"); } if(t_date === sh_alldata.getRange(7, 1).getValue()){ console.log("1:t_date ===sh_alldata.getRange(7, 1).getValue()"); } if(t_date === test_date){ console.log("1:t_date ===test_date"); }
2023/05/10 10:43:02 デバッグ Wed May 10 2023 10:42:59 GMT+0900 (Japan Standard Time) 2023/05/10 10:43:02 デバッグ Wed May 10 2023 10:42:59 GMT+0900 (Japan Standard Time) 2023/05/10 10:43:02 デバッグ Wed May 10 2023 10:42:59 GMT+0900 (Japan Standard Time) 2023/05/10 10:43:02 デバッグ Wed May 10 2023 10:42:59 GMT+0900 (Japan Standard Time)
test_date.setHours(0, 0, 0, 0); t_date.setHours(0, 0, 0, 0); console.log(t_date); console.log(test_date); if(timestamp === test_date){ console.log("2:timestamp ===test_date"); } if(t_date === sh_alldata.getRange(7, 1).getValue()){ console.log("2:t_date ===sh_alldata.getRange(7, 1).getValue()"); } if(t_date === test_date){ console.log("2:t_date ===test_date"); }
2023/05/10 10:43:02 デバッグ Wed May 10 2023 00:00:00 GMT+0900 (Japan Standard Time) 2023/05/10 10:43:02 デバッグ Wed May 10 2023 00:00:00 GMT+0900 (Japan Standard Time)
