简体   繁体   English

如何在Excel中计算单个单元格的当前日期和时间?

[英]How do i calculate the current date and time for single cell in excel?

How do i calculate the current date and time in excel? 如何在Excel中计算当前日期和时间? I have first column Name, second Date and third Time. 我有第一列名称,第二个日期和第三时间。 The problem is when i change the name column, all previous entries of date and time change to the current one. 问题是当我更改名称列时,日期和时间的所有先前条目都更改为当前条目。

Eg 例如

Name      Date      Time
George    7/6/2017  20:45
John      7/6/2017  20:45
Michael

If i change the next cell to Michael, all above entries change to the same date and same current time 如果我将下一个单元格更改为Michael,则以上所有条目均更改为同一日期和当前时间

Name      Date      Time
George    7/6/2017  20:49
John      7/6/2017  20:49
Michael   7/6/2017  20:49

Here is the function for the calculation of the time: 这是用于计算时间的函数:

=IF($J4<>0, NOW(),)

Here is the function for the calculation of the date: 这是用于计算日期的函数:

=IF($J4<>0,TODAY(),)

How do i fix this, thanks? 谢谢,我该如何解决?

NOW() and TODAY() are functions. NOW()TODAY()是函数。 Whenever the worksheet recalculates - which happens, by default, whenever a value is entered into a cell, the results of these formulas will also change. 每当工作表重新计算时-默认情况下,每当在单元格中输入一个值时,这些公式的结果也会改变。

To insert the current date into a cell you can use the shortcut Ctrl-; 要将当前日期插入单元格,可以使用快捷键Ctrl-; , and Ctrl-Shift-; ,以及Ctrl-Shift-; for the current time. 当前时间。 These are fixed values and won't change after being entered. 这些是固定值,输入后不会更改。


It is possible to work with fixed values and formulas. 可以使用固定值和公式。

  • switch to manual calculation 切换到手动计算
  • fill in the rows, leaving the date/time formulas intact 填写行,保持日期/时间公式不变
  • copy/paste special, values, all the date/time formulas 复制/粘贴特殊,值,所有日期/时间公式
  • switch back to automatic calculation 切换回自动计算

This is a risky strategy though. 不过,这是一个冒险的策略。 If you don't follow it exactly you could end-up with all the dates/times having the same value, with no way to reinstate the entered dates/times. 如果您不完全遵循它,那么最终所有的日期/时间都具有相同的值,而无法恢复输入的日期/时间。 It isn't worth the risk when the keyboard shortcuts are available. 键盘快捷键可用时,不值得冒险。

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

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