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.
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
.
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)
.
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.
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
.
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.
Please try:
=INT(A2)
and format the result to suit.
In a comment I have just seen you mention "=INT(A2) return #VALUE!" so I would suggest selecting your date cells, DATA > Data Tools, - Text to Columns, Delimited, Delimiters Tab (only), and at Step 3 of 3 choose MDY for Date: or change your locale to say USA.
If neither work try =INT(TRIM(A2)) in case you have leading spaces (though not showing them).
If still not working, try applying =CLEAN
.
If still nothing works then some further details of where your dates are coming from and how imported would be helpful, and of your locale and default date format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With