简体   繁体   English

将日期时间字符串转换为 excel 中的日期

[英]Convert date-time string to Date in excel

I have two columns with date-time values such as "2019-08-15T00:45:28.228Z".我有两列包含日期时间值,例如“2019-08-15T00:45:28.228Z”。 I want to convert each of them into date format columns, and then find number of minutes between the dates.我想将它们中的每一个转换为日期格式列,然后找到日期之间的分钟数。

eg:例如:


| A1                       | A2                       | Date(A1) | Date(A2) | A2-A1 in minutes |
|--------------------------|--------------------------|----------|----------|------------------|
| 2019-08-15T00:45:28.228Z | 2019-08-15T00:55:28.228Z |          |          | 10               |
| 2019-07-25T00:45:45.127Z | 2019-07-25T01:25:55.127Z |          |          | 40               |

I have not been able to convert the columns into a date format, because it has a time element as well, and all online examples seem to be only for date我无法将列转换为日期格式,因为它也有时间元素,所有在线示例似乎都只针对日期

You can use LEFT function to retrieve the date (it will then be displayed in its original format, like 2019-08-15 ), or simply do --LEFT to convert the result to a number and change its formatting to Date using Excel:您可以使用LEFT function 检索日期(然后它将以其原始格式显示,如2019-08-15 ),或者简单地执行--LEFT将结果转换为数字并使用 Excel 将其格式更改为Date

在此处输入图像描述

Then use MID function to retrieve the times and do your A2-A1 calculation (format the last column as Time ):然后使用MID function 检索时间并进行A2-A1计算(将最后一列格式化为Time ):

在此处输入图像描述

Update - as per Paul's suggestion, the length of the syntax will always be the same so you could use the following functions:更新- 根据 Paul 的建议,语法的长度将始终相同,因此您可以使用以下函数:

=--LEFT(A2,10)
=MID(A2,12,12)

To get the data time all we need to do is remove the T and the Z so:要获得数据时间,我们需要做的就是删除 T 和 Z,这样:

=--REPLACE(LEFT(A2,23),11,1," ")

Then format to the desired format.然后格式化为所需的格式。

在此处输入图像描述

Then a simple subtraction of the dates and a format of [mm] will return the desired output.然后简单地减去日期和格式[mm]将返回所需的 output。

在此处输入图像描述

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

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