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.
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.
Date macros are depending on the system date format and based on configured system date format the macros can fail to work. Try below solution. We faced similar issue after open excel file sent by me on another laptop where system date/time format was different. On destination laptop formulas using date functions started giving error. After following below steps errors disappeared.
Left click on bottom right portion of task bar where time is displayed
Click on date and time settings
Click on change date and time
Change calendar settings
Click on reset to go back to original values
Click on OK on all opened dialogues
Now excel formula error should disappear
SIMPLE SOLUTION - I found a solve that worked very well:
=DATEVALUE(TEXT([CELL],"MM/DD/YYYY")
Effectively this lets me convert any value into text, then back into date. It fixed my Datevalue error and I can use it regardless of the original cell formatting.
Related
How do I separate date and time from this 2006-09-02T01:07:59.100 I’ve tried =int(A2) but it gives a value error. Please help.
in the column for Date put this formula: =left(A2,10), for the time: =right(A2,12)
Not sure what your purpose is. Display date and time separately or actually have two different values in different cells.
Excel does not play nice with "T" in the middle of the timestamp. You must remove "T" using a string function. Once you have done that your value will format nicely as a date. INT works for the date part, MOD works for time, format cells accordingly.
If display is the only requirement, put the same value in both cells and use cell formatting -- one for Date, one for Time.
So I have been stuck at this weird error with excel 2010. I have the following data at cell A4 which is a reference to another cell B1, which is a start date entered by user, and I am trying to get day name by using the formula
=CHOOSE(WEEKDAY(B4),"Su","Mo","Tu","We","Th","Fr","Sa"), yet it gives an error with no real clues. Also I have tried
=Text(B4, "dddd")
and it gives an error as well.
Any ideas?
The issue is that, depending on regional settings, you should use semicolon ; instead of comma , as separator in formulas.
I have encountered the same error myself. The problem is not in the CHOOSE function, but in the WEEKDAY function.
It turns out that the WEEKDAY function is expecting very strict date formats and is influenced by the system's date format.
As stated in the cell's date format panel:
NOTE: Date formats that begin with an asterisk (*) will change if you change the regional date and time settings in Control Panel. Formats without an asterisk won’t change.
The solution is to change the date cell's format to a strict date format, one of the formats in the list without a * symbol, and then entering a date in the format of 01-JAN-2018.
As you can see in the image below, this solved my problem:
My data is extracted from an application and it has a text that looks like a date/time in excel. How do I actually convert "3/24/2016 11:22:07 PM" (in text) to a real date/time conversion? I've tried formatting the cells but it doesn't work.
For a date conversion:
=DATEVALUE(TEXT(A1,"MM/DD/YYYY"))
For a time conversion:
=TIMEVALUE(TEXT(A1,"HH:MM:SS"))
For datetime conversion:
=DATEVALUE(TEXT(A1,"MM/DD/YYYY"))+TIMEVALUE(TEXT(A1,"HH:MM:SS"))
Where A1 has the data you wish to convert.
By the way, then you may wish to format the cell to a date/time or whatever.
Hope that helps.
1) try using the DATEVALUE function and see if that works for you.
2) A more reliable way, since datevalue does not always work is to strip the text out manually and insert it into and excel date value. You are going to want to use a combination of the following functions:
DATE
TIME
IF
FIND
MID
LEFT
RIGHT
LEN
Now in my opinion the easiest way to do this is to work with multiple helper columns to build out all the steps. One column per step. When you get your final answer, you can substitute or copy paste your formulas from the helper columns into the final formula until you are left with one variable. The reason I say this is that the final formula referring to only 1 variable gets rather lengthy/ugly and very hard to trouble shoot if you make a typo, forget a bracket or something goes wrong. When I did this approach I used a totally of 14 columns (includes final formula). When I packed it all up into 1 formula it resulted in this:
DATE(RIGHT(LEFT(A3,FIND(" ",A3)-1),4),LEFT(LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))-1),MID(LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))+1,FIND("/",LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))+1)-FIND("/",LEFT(A3,FIND(" ",A3)-1))-1))+TIME(LEFT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1)+IF(AND(LEFT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1)<12,RIGHT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),2)="AM"),0,12),MID(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1,FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1)-FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1),MID(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1)+1,2))
Note it is set up using cell A3 as the one with the time as text that needs formatting.
3) You should also be able to use excel's text to column function located on the DATA ribbon about half way across.
4) And of course there will be a way to code it through VBA as an option as well.
=DATEVALUE(A1)+TIMEVALUE(A1) seems to work as well, since each function only returns the value corresponding to what it recognizes in the string. That is, DATEVALUE() ignores the time component, while TIMEVALUE() ignores the date component.
I am not sure if I am just over looking something, because I am still a very newbie to Excel's functions, so here comes the problem :
Lets say that I have A1 cell, and I want to display todays date in another cell whenever the A1 cell isn't empty.
So I came with this :
in another cell :
IF(A1<>"";TODAY();"")
Todays date is 16.8.2015, but when I run TODAY() through a condition like this, the output is : 42232
Why would I get this weird number ?
Maybe I did syntax wrong ? Not sure.. I also tried to make =TODAY() in new cell, that displayed the 16.8.2015, and then I wanted to show that cell through that condition, it threw the "42232" again.
Be sure that the cell format is Date and not General or Number.
The TODAY function returns a serial number which is equivalent to the amount of days since 1/1/1900. That is why you are seeing the number instead of the date.
Select the cell with the number and on the Home tab you can change the format to Date (See Below).
Every date in Excel is represented by a number. For example, the number 1 represents 1/1/1900. Whereas 42232 represents 8/16/2015.
Here is a list of dates:
04-22-11
12-19-11
11-04-11
12-08-11
09-27-11
09-27-11
04-01-11
When you copy this list in Excel, some of them are recognized as dates, others not, in the following manner:
04-22-11
12-19-11
11-04-11 (date)
12-08-11 (date)
09-27-11
09-27-11
04-01-11 (date)
Does anyone know why? And how to force Excel to recognize all list items as dates?
Many thanks!
It is caused by Excel auto-recognizing/formatting the cell contents, but in unclear/inconsistent ways.
Fixing it is not that hard...
Check out this forum post:
http://www.pcreview.co.uk/forums/excel-not-recognizing-dates-dates-t3139469.html
The steps in short:
Select only the column of "dates"
Click Data > Text to Columns
Click Next
Click Next
In step 3 of the wizard, check "Date" under Col data format, then
choose: "DMY" from the droplist.
Click Finish
This is caused by the regional settings of your computer.
When you paste data into excel it is only a bunch of strings (not dates).
Excel has some logic in it to recognize your current data formats as well as a few similar date formats or obvious date formats where it can assume it is a date. When it is able to match your pasted in data to a valid date then it will format it as a date in the cell it is in.
Your specific example is due to your list of dates is formatted as "m/d/yy" which is US format. it pastes correctly in my excel because I have my regional setting set to "US English" (even though I'm Canadian :) )
If you system is set to Canadian English/French format then it will expect "d/m/yy" format and not recognize any date where the month is > 13.
The best way to import data, that contains dates, into excel is to copy it in this format.
2011-04-22
2011-12-19
2011-11-04
2011-12-08
2011-09-27
2011-09-27
2011-04-01
Which is "yyyy-MM-dd", this format is recognized the same way on every computer I have ever seen (is often refered to as ODBC format or Standard format) where the units are always from greatest to least weight ("yyyy-MM-dd HH:mm:ss.fff") another side effect is it will sort correctly as a string.
To avoid swaping your regional settings back and forth you may consider writting a macro in excel to paste the data in. a simple popup format and some basic logic to reformat the dates would not be too difficult.
In your case it is probably taking them in DD-MM-YY format, not MM-DD-YY.
The quickest and easiest way to fix this is to do a find and replace on your date seperator, with the same separator.
For example in this case Find "-" and Replace with "-", not sure why this works but you will find all dates are right-aligned as they should be after doing this.
Here is what worked for me. I highlighted the column with all my dates. Under the Data tab, I selected 'text to columns' and selected the 'Delimited' box, I hit next and finish. Although it didn't seem like anything changed, Excel now read the column as dates and I was able to sort by dates.
The simplest solution is to put yy,mm,dd into the date() formula by first extracting them with left(), mid() and right(). In this case, assuming your input date is in A1:
=date(right(A1,2)+100,left(A1,2),mid(A1,4,2))
Explanation of above:
=right(A1,2) gets the last two digits in the cell (yy). We add 100 because it defaults to 1911 instead 2011 (omit +100 if it doesn't do that on yours)
=left(A1,2) gets the first two digits in the cell (mm).
=mid(A1,4,2) gets 2 digits in the middle of the cell, starting at 4th digit (dd).
Why this happens in the first place:
I come across this problem all the time when I import Canadian bank data into excel. In short, your input date format does not match your regional settings.
Seems your setting mean Excel wants date input as either DD-MM-YY or YY-MM-DD, but your input data is formatted as MM-DD-YY.
So, excel sees your days as months and vice-versa, which means any date with day below 12 will be recognized as a date, BUT THE WRONG DATE (month and day reversed) and any date with day above 12 won't be recognized as a date at all, because Excel sees the day as a 13th+ month.
Unfortunately, you can't just change the formatting, because Excel has already locked those day/month assignments in place, and you just end up moving what Excel THINKS are days and months around visually, not reassigning them.
Frankly, it is surprising to me there is not a date-reverse tool in excel, because I would think this happens all the time. But the formula above does it pretty simply.
NOTE: if your dates don't have leading zeros (i.e. 4/8/11 vs 04/08/12) it gets trickier because you have to extract different amounts of digits depending on the date (i.e. 4/9/11 vs 4/10/11). You then have to build a couple if statements in your formula. Gross.
Here is what worked for me on a mm/dd/yyyy format:
=DATE(VALUE(RIGHT(A1,4)),VALUE(LEFT(A1,2)),VALUE(MID(A1,4,2)))
Convert the cell with the formula to date format and drag the formula down.
Right-click on the column header and select Format Cells, the chose Date and select the desired date format. Those that are not recognized are ambiguous, and as such not interpreted as anything but that is resolved after applying formatting to the column. Note that for me, in Excel 2002 SP3, the dates given above are automatically and correctly interpreted as dates when pasting.
A workaround for this problem consists in temporarily changing your regional settings, so the date format of the CSV imported file "matches" the regional settings one.
Open Office seems to work in a similar way for that issue, see: http://www.oooforum.org/forum/viewtopic.phtml?t=85898
I come across this problem when I tried to convert to Australian date format in excel. I split the cell with delimiter and used the following code from split cells then altered the issue areas.
=date(dd,mm,yy)