使用DATEVALUE函数时Excel #Value错误 [英] Excel #Value error when using DATEVALUE function

查看:141
本文介绍了使用DATEVALUE函数时Excel #Value错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单元格 A2 我有 7/21/2014 12:44:36 PM



当我使用 DATEVALUE(LEFT(A2; FIND(; A2)-1))我得到错误 #VALUE



当我使用 LEFT(A2; FIND(; A2)-1 )我得到 7/21/2014



我需要做什么函数 DATEVALUE(LEFT(A2; FIND(; A2)-1))只返回日期?

解决方案

虽然时间元素仍然存在于单元格中。我假设你知道这一点,但是由于你没有指定,这是一个可能的解决方案。


In cell A2 I have 7/21/2014 12:44:36 PM

When I use DATEVALUE(LEFT(A2;FIND(" ";A2)-1)) I get the error #VALUE.

When I use LEFT(A2;FIND(" ";A2)-1) I get 7/21/2014.

What do I need do that function DATEVALUE(LEFT(A2;FIND(" ";A2)-1)) to return just the date?

解决方案

DATEVALUE() is designed to make a Date out of plain text. Your cell is currently a Date/Time, which is a numeric value. I recommend using one of the following solutions to get the date from the cell.

Using DATE()


This is the cleanest option and the method that I would recommend.

=DATE(YEAR(A2),MONTH(A2),DAY(A2))

YEAR() gets the Year value from the cell, MONTH() gets the Month value, and DAY() gets the Day value. The DATE() function takes a Year, Month, and Day value, so by passing them into DATE() we can get the Date value from A2.

Using INT()


If we look at the numeric value of your Date in A2, we see that it is 41841.5309722222. The whole portion of the number (41841.) is the date and the decimal portion (.5309722222) is the time. So if we take INT(A2) to convert this value to an integer, we will lose the decimal portion so that all that remains (41841) is the date. So this is our formula for using INT()

=INT(A2)

The same idea can be accomplished with ROUNDDOWN(A2,0) or =FLOOR.MATH(A2) or =FLOOR(A2,1).

Using DATEVALUE()


While the first solution is the cleanest, there is a way to do this with DATEVALUE() that involves converting the cell into Text first. The TEXT() function takes a value and a format string, so we format the cell value as Text as follows

=TEXT(A2,"yyyy-mm-dd")

And this gives us

2014-07-21

We then pass that result into DATEVALUE()

=DATEVALUE(TEXT(A2,"yyyy-mm-dd"))

You will need to format the result as a date.

Using LEFT() and DATEVALUE()


Based on this Stackoverflow question that I found, it appears the issue could be a result of inconsistent formatting, so you might try this solution

=DATEVALUE(LEFT(A2,FIND(" ",A2)-1))

I have included my results with this and the other methods in a screenshot below. You can see by my use of the TYPE() command below the value that I tested this on both a number and text.

Results

Formatting


I'm assuming you want just the date for calculation purposes, but if you just want to display the date, you can format the cell to only show the date and ignore the time element although the time element will still be present in the cell. I'm assuming you know about this, but since you didn't specify, it is a possible solution.

这篇关于使用DATEVALUE函数时Excel #Value错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆