Google Apps脚本:比较日期 [英] Google Apps Script: comparing dates
本文介绍了Google Apps脚本:比较日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在比较Google Apps脚本中的日期时遇到了一个奇怪的问题.
I'm having a weird issue comparing dates in my Google Apps Script.
为此,我的工作表在cell.getValue()中有一个日期,所以
For this, my sheet has a date in cell.getValue() so on the
e.range.setNote(cell.getValue() + " --- " + startDate);
行中,注释显示了两个看起来相同的日期,但是它们不是因为以下if语句不满足而引起的.我在比较中是否缺少某些内容?谢谢.
line, the note shows two dates that appear identical, but they aren't because the following if statement is not satisfied. Am I missing something here with the comparisons? Thanks.
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sss = ss.getSheetByName("Sheet1");
var row = e.range.getRow();
var startDate = sss.getRange(row, 3).getValue(); //Wed Aug 10 2016 00:00:00 GMT-0600 (GALT)
var cell = ss.getSheetByName("Sheet2").getRange(1, 1);
e.range.setNote(cell.getValue() + " --- " + startDate); //Wed Aug 10 2016 00:00:00 GMT-0600 (GALT) --- Wed Aug 10 2016 00:00:00 GMT-0600 (GALT)
if (cell.getValue() === startDate){
cell.setBackground('blue');
}
}
推荐答案
我认为您需要将日期进行比较 https://stackoverflow .com/a/493018/1393023
I think you need to compare as dates https://stackoverflow.com/a/493018/1393023
替换
cell.getValue() === startDate
到
cell.getValue().getTime && startDate.getTime && cell.getValue().getTime() === startDate.getTime()
这篇关于Google Apps脚本:比较日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文