跳到主要内容

在Excel中快速自动插入日期和时间戳

在Excel中,插入日期和时间戳是正常操作。 在本教程的此处,我将通过提供不同的情况介绍在Excel单元格中手动或自动插入日期和时间戳的多种方法。

使用快捷方式插入日期和时间戳

使用公式插入日期和时间戳

在另一列中输入数据时自动插入时间戳的公式

VBA在另一列中输入数据时自动插入时间戳


使用快捷方式插入日期和时间戳

如果只需要在几个单元格中插入日期和时间戳,则可以通过按快捷键手动插入它们。

插入当前日期: 系统 + :
doc插入时间戳1

插入当前时间: 转移 + 系统 + :
doc插入时间戳2

看截图:
doc插入时间戳3

提示:

1.您可以根据需要将输出格式设置为日期格式或时间格式。 单元格格式 对话。

2。 如果你有 Kutools for Excel,您可以根据需要将当前日期或其他日期以指定的日期格式插入 插入日期 功能。 点击免费下载
插入日期


使用公式插入日期和时间戳

如果要插入可以自动更新的日期或时间戳,可以使用以下公式。

插入当前日期

= TODAY()

媒体 输入 键,并将当前日期插入到单元格中。

插入当前时间:

=现在()

按Enter键,当前日期和时间将插入到单元格中。
doc插入时间戳4

提示:

1.您可以根据需要将输出格式设置为日期格式或时间格式。 单元格格式 对话。 例如,您只想显示当前时间,只需在使用 =现在() 公式

2.如果要将当前日期和时间插入工作表的页眉或页脚,则可以使用 插入工作簿信息 功能 Kutools for Excel 快速处理这项工作。 点击免费下载
插入工作簿信息


在另一列中输入数据时自动插入时间戳的公式

假设有两列,即A列和B列,现在您想在A列中输入数据时在B列中插入当前时间戳,该如何做?
自动插入timstamp 1

输入数据时自动插入时间戳

1.首先,单击 文件 > 附加选项 打开 Excel选项 对话框中,选择 公式 在左窗格中,然后检查 启用迭代计算 in 计算选项 组。 然后点击 OK.
doc插入时间戳5

2.在B列(例如,单元格B1)中,键入以下公式

= IF(A1 <>“”,IF(B1 <>“”,B1,NOW()),“”)

然后将自动填充手柄向下拖动到单元格。
doc插入时间戳6

3.然后根据需要在公式中将公式单元格设置为日期时间格式。 单元格格式 对话框:保持公式单元格处于选中状态,右键单击以显示上下文菜单,选择 单元格格式,则 单元格格式 对话框弹出 定制版 在哪个部分 联系电话 标签,在中输入所需的格式 Type 文本框,然后单击 OK.
doc插入时间戳7

现在,当您在列A中输入数据时,当前日期时间将插入到列B中。
doc插入时间戳8

当单元格在另一列中更改时自动插入和更新时间戳

如果要在单元格输入时自动插入时间戳,并且同时更改条目,则插入的时间戳将被更新,可以使用以下公式:

=IF(A1<>"",IF(AND(B1<>"",CELL("address")=ADDRESS(ROW(A1),COLUMN(A1))),NOW(),IF(CELL("address")<>ADDRESS(ROW(A1),COLUMN(A1)),B1,NOW())),"")

A1是您将输入数据的单元格,B1是您要插入时间戳的公式的单元格。

将自动填充手柄向下拖动到您使用的单元格上。
自动插入timstamp 2

然后,根据需要在公式单元格中将其设置为日期时间格式 单元格格式 对话框:保持公式单元格处于选中状态,右键单击以显示上下文菜单,选择 单元格格式,则 单元格格式 对话框弹出 定制版 在哪个部分 联系电话 标签,在中输入所需的格式 Type 文本框,单击 OK.


VBA在另一列中输入数据时自动插入时间戳

如果您熟悉VBA代码,则可以执行以下操作:

1.右键单击您使用的工作表选项卡,然后选择 查看代码 从上下文菜单。
doc插入时间戳9

2.然后在 Microsoft Visual Basic应用程序 窗口,粘贴下面的代码。

VBA:自动插入时间戳

Private Sub Worksheet_Change(ByVal Target As Range)
'UpdatebyKutools20190919
Dim xRInt As Integer
Dim xDStr As String
Dim xFStr As String
On Error Resume Next
xDStr = "A" 'Data Column
xFStr = "B" 'Timstamp Column
If (Not Application.Intersect(Me.Range(xDStr & ":" & xDStr), Target) Is Nothing) Then
       xRInt = Target.Row
       Me.Range(xFStr & xRInt) = Format(Now(), "mm/dd/yyyy hh:mm:ss")
End If
End Sub

doc插入时间戳10

3.然后保存此代码。 从现在开始,只要您在A列中输入数据或更改数据,新的时间戳就会插入到B列中。

备注:您可以在VBA代码中更改A和B列以及mm / dd / yyyy hh:mm:ss时间格式,以符合您的实际需求。

如果要使用定义的函数,可以执行以下操作:

1.按住 Alt + F11键 启用 Microsoft Visual Basic应用程序 窗口。 然后点击 插页 > 模块 插入空白模块。
doc插入时间戳11

2.将下面的代码粘贴到新模块中。 然后保存代码并返回工作表。

Function FormatDate(xRg As Range)
'UpdatebyKutools20190919
On Error GoTo Err_01
If xRg.Value <> "" Then
    FormatDate = Format(Now, "mm/dd/yyyy hh:mm:ss")
Else
    FormatDate = ""
End If
Exit Function
Err_01:
    FormatDate = "Error"
End Function

doc插入时间戳12

3.在将插入时间戳的单元格中,键入此公式

= FormatDate(F1)

F1是您要输入数据或更改数据的单元格。 然后将自动填充手柄向下拖动到单元格。
doc插入时间戳13

现在,如果单元格F1输入数据或已更新,则将插入当前日期时间。


与DateTime相关的其他操作(文章)

将存储为文本的日期转换为Excel中的日期
有时,当您将日期从其他数据源复制或导入到Excel单元格时,日期可能会格式化并存储为文本。 在这里,我介绍了一些技巧,可以将这些以文本形式存储的日期转换为Excel中的标准日期。

在Excel中添加或减去半年/月/小时的日期或时间
在我们的Excel日常工作中通常要添加年,月或小时的日期或时间。 您是否曾经尝试添加半年,一个月或一个小时的日期或时间? 在这里,我介绍了处理此工作的技巧。

Excel中一天的平均时间戳
例如,您已经记录了特定用户每次在Excel中访问网站时的登录时间戳,现在您希望将这些时间戳取平均值,以预测该用户将来访问该网站的最长时间,如何完成它? ?

在Excel中计算午夜之后的时间之间的小时数
假设您有一个时间表来记录您的工作时间,则A列中的时间是今天的开始时间,B列中的时间是第二天的结束时间。 通常,如果您直接减去“ = B2-A2”来计算两次之间的时间差,则不会显示正确的结果


  • 超级公式栏 (轻松编辑多行文本和公式); 阅读视图 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 和保存数据; 拆分单元格内容; 合并重复的行和总和/平均值...防止细胞重复; 比较范围...
  • 选择重复或唯一 行; 选择空白行 (所有单元格都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择...
  • 确切的副本 多个单元格,无需更改公式参考; 自动创建参考 到多张纸; 插入项目符号,复选框等...
  • 收藏并快速插入公式,范围,图表和图片; 加密单元 带密码 创建邮件列表 并发送电子邮件...
  • 提取文字,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级筛选 (将过滤方案保存并应用于其他工作表); 高级排序 按月/周/日,频率及更多; 特殊过滤器 用粗体,斜体...
  • 结合工作簿和工作表; 根据关键列合并表; 将数据分割成多个工作表; 批量转换xls,xlsx和PDF...
  • 数据透视表分组依据 周号,周几等 显示未锁定的单元格 用不同的颜色 突出显示具有公式/名称的单元格...
kte选项卡201905
  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
officetab底部
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
If anyone can assist, I'm seeking help to create a formula that, when I change the status to 'Complete,' automatically records the date of that moment. Similarly, if I change the status for subsequent entries, it should capture the date of that day. Any guidance on creating this formula would be greatly appreciated.
This comment was minimized by the moderator on the site
Hi, We have used the following formula for auto-update timestamp

=IF(A1<>"",IF(AND(B1<>"",CELL("address")=ADDRESS(ROW(A1),COLUMN(A1))),NOW(),IF(CELL("address")<>ADDRESS(ROW(A1),COLUMN(A1)),B1,NOW())),"")

But, sometimes it works sometimes it doesn't. even faced for some user's it's working fine for some not.
Sometimes it shows circular reference pop message error for some-user.
when tried to rectify the error, we saw circular reference is grad out. Not sure how do we fix it.

Any help much apricated!!! Thankyou
This comment was minimized by the moderator on the site
Hi, thank you for this, it is very helpful with my project.

I' m running calculations on stock market information that is populating the spreadsheet with RTD;
I' m trying to create a timestamp when there is an update in the stock price, but this does not work, the "timestamp" cell remains blank.
(The cell that receives the stock price is RTD formula)

Any ideas what i should do ?
This comment was minimized by the moderator on the site
In the cells where the time stamp should show up, red text saying Time stamp shows up instead. No value in format mm/dd/yyyy hh:mm:ss is visible.
This comment was minimized by the moderator on the site
Hi, Celeste, I did not get your question clearly. If you want to show "Time Stamp" in the cell if there is empty in the entried cell, you just change the formula to:
=IF(A1<>"",IF(B1<>"",B1,NOW()),"Time Stamp")
This comment was minimized by the moderator on the site
the function uptades every time you open the excel file
it also updates the earlier data when you insert rows.
This comment was minimized by the moderator on the site
Hi, try to click Formulas tab and go to Calculation group to click Calculation Options > Manual, then the formula will not auto update.
https://www.extendoffice.com/images/stories/comments/sun-comment/doc-manual-calculation.png
This comment was minimized by the moderator on the site
Thank you very much for your kind help. Unfortunately, the manual setting would stop my other formulas in the table, which is not good from my point of view.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations