简体   繁体   English

在 excel 中从文本转换为日期格式

[英]convert from text to date format in excel

I have 2 text as below want to convert to date in excel我有 2 个文本如下想在 excel 中转换为日期

2/10/2001 4:00:00 AM    
2/10/2001 12:30:00 PM

I tried =DATEVALUE() and TEXT(A1, "mm/dd/yyyy hh:mm") in excel which returns me error我在 excel 中尝试了 =DATEVALUE() 和 TEXT(A1, "mm/dd/yyyy hh:mm") ,这返回了我的错误

在此处输入图像描述

I also tried to calculate these 2 dates which also return me error我还尝试计算这两个日期也返回错误

在此处输入图像描述

Try below formula试试下面的公式

=TEXT(--LEFT(A1,SEARCH(" ",A1)-1)+(--MID(A1,SEARCH(" ",A1)+1,100)),"mm/dd/yyyy hh:mm:ss AM/PM")

This simple formula should also work- format the resulting cell as mm/dd/e hh:mm:ss AM/PM这个简单的公式也应该将结果单元格格式化为mm/dd/e hh:mm:ss AM/PM

=TRIM(DATEVALUE(A1))+TRIM(TIMEVALUE(A1))

FILTERXML() will also work. FILTERXML()也可以。

=TEXT(SUM(FILTERXML("<t><s>"&SUBSTITUTE(TRIM(A1)," ","</s><s>")&"</s></t>","//s[position()<3]")),"mm/dd/e hh:mm:ss AM/PM")

在此处输入图像描述

I'm not sure I understand the question.我不确定我是否理解这个问题。 When you enter those values into a spreadsheet, Excel understands them as date/time values.当您将这些值输入电子表格时,Excel 将它们理解为日期/时间值。 No conversion is necessary.无需转换。 You can perform date/time arithmetic on them as is.您可以按原样对它们执行日期/时间算术。

在此处输入图像描述

Cell A1 & B1 show the values I copied from your question and pasted into the worksheet.单元格 A1 和 B1 显示我从您的问题中复制并粘贴到工作表中的值。 C1 shows the time interval in hours. C1 以小时为单位显示时间间隔。

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

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