简体   繁体   English

添加日期+时间而不是 12AM 移动到第二天

[英]Adding Date+Time without 12AM moving to the next day

I am using the attached to automate a time entry to go along with the date for a calendar import.我正在使用附件自动输入 go 的时间以及日历导入的日期。 The entries don't have times, and the staff will not enter them try as I might.条目没有时间,工作人员不会像我一样尝试输入它们。 I need to automate them to simplify the entry procedure.我需要使它们自动化以简化输入程序。

The issue I am facing is that the Calendar API needs the data to be in DATE/TIME format.我面临的问题是日历 API 需要数据采用 DATE/TIME 格式。 To do this I need to use the =DATE+TIME formula.为此,我需要使用 =DATE+TIME 公式。 When I do so and the time reaches 12:00AM, the dates thereafter change to the following day.当我这样做并且时间到达 12:00AM 时,此后的日期将更改为第二天。

Essentially I need to either override the logic that makes it move into the next day after midnight appears, or I need to tell either the function in column BC that it can never roll to midnight.本质上,我需要覆盖使其在午夜出现后进入第二天的逻辑,或者我需要告诉 BC 列中的 function 它永远不会滚动到午夜。 I am trying to think of perhaps a way that I can tell the function to reset the time if the date in column A changes to a new day, and if it doesn't change to a new day go ahead and use the existing function and add 5 minutes to the time that is shown previously to it.我正在尝试考虑一种方法,如果 A 列中的日期更改为新的一天,并且如果它没有提前更改为新的一天 go 并使用现有的 function 和将之前显示的时间增加 5 分钟。

I am stumped, any help would be greatly appreciated.我很难过,任何帮助将不胜感激。

Here is a sheet to show you the issue 这是一张向您展示问题的表格

Here is the formula I tried, which worked to sort out the problem but did not work with the Calendar API requirements to format at DATE/TIME.这是我尝试过的公式,它可以解决问题,但不适用于日历 API 在 DATE/TIME 格式化的要求。 Even when using the importrange formula to move the data into a new sheet with the cells formatted as DATE/TIME it still recognizes it as TEXT as this is what the formula prescribes.即使使用 importrange 公式将数据移动到单元格格式为 DATE/TIME 的新工作表中,它仍然将其识别为 TEXT,因为这是公式规定的。

=IF(A2<>"",(CONCATENATE(TEXT(A2,"MM/DD/YYYY")&" "&TEXT(B2,"HH:MM:SS"))),"") =IF(A2<>"",(CONCATENATE(TEXT(A2,"MM/DD/YYYY")&" "&TEXT(B2,"HH:MM:SS"))),"")

I need this to work in both the sheet and in the import to Calendar using the Calendar API requirements through APPScript.我需要通过 APPScript 使用 Calendar API 要求在工作表和日历导入中使用它。

If I understood correctly your question, here a suggestion with a custom Apps Script function called like a normal Google Sheet function.如果我理解正确你的问题,这里有一个自定义 Apps 脚本 function 的建议,就像普通的 Google 表格 function 一样。

  • Open Apps Script Editor and paste the function below打开 Apps 脚本编辑器并粘贴下面的 function
  • Call the function rebuildDateTime(COL1, COL2) inside your spreadsheet在电子表格中调用 function rebuildDateTime(COL1, COL2)

Spreadsheet:电子表格:

带有自定义公式的电子表格的屏幕截图

Code:代码:

function rebuildDateTime(arg0, arg1) {

  var date = new Date(arg0);
  var str = arg1.toString().split(':');
  date.setHours(str[0]);
  date.setMinutes(str[1]);

  return date;
} 

Warning:警告:

  • Your COL2 (which contains only the time), must be forced to TEXT FORMAT您的 COL2(仅包含时间)必须强制为 TEXT FORMAT

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM