I had a bad time trying to import some excel data, then I found that there's a problem with a date field.
I thought the field is string-date text, but when I try to convert it to real-date, not all data convert well Here's a sample below
I tried to format cells, didn't work. Then tried
1- DATEVALUE and VALUE functions
2- ADD zero
3- DELIMITED text to columns
but nothing appears to work. What is this type of data?? and how to convert to real text?
appreciate your help.
In B2 enter:
=IFERROR(VALUE(A2),DATE(RIGHT(A2,4),MID(A2,4,2),RIGHT(A2,2)))
EDIT#1:
Fixed Formula and format:
=IFERROR(VALUE(A2),DATE(RIGHT(A2,4),MID(A2,4,2),LEFT(A2,2)))
If one has textjoin:
=--TEXTJOIN("/",,FILTERXML("<a><b>"&SUBSTITUTE(TEXT(A1,"mm/dd/yyyy"),"/","</b><b>")&"</b></a>","//b["&{2,1,3}&"]"))
If not then parse the TEXT:
=DATE(RIGHT(TEXT(A1,"mm/dd/yyyy"),4),MID(TEXT(A1,"mm/dd/yyyy"),4,2),LEFT(TEXT(A1,"mm/dd/yyyy"),2))
Solved it!!
I needed to change my machine date format, I am not certain but here's what I think was the problem.Because the data was a string-date not a real date, so excel took format of my machine which was mm/dd/yyyy. so for the first date 20/01/2000, excel cannot put 20 as a month when I try to change format or run (text to column) or result in error in DATEVLUE and VALUE, so lots of dates didn't get formatted or resulted in error. On the other hand, the second date, 07/02/2002, can be formatted and functions work well.
So, changing my machine format to dd/mm/yyyy solved the issue and data converted with simple Text to Column.
Big Credit for #ScottCraner
Related
I have a date field where the format is (example) 20170101.
When I try to convert this field to short date, it comes up as "###".
I need the date in the format of 1/1/2017.
Can someone help?
Thanks!
The data is not a date but a number and by simply changing the format will try to return a date that is 20,170,101 days from 1/1/1900. And Excel stops recognizing dates after 12/31/9999. This would be well beyond that, roughly 45 thousand years beyond that.
you can use a helper column with the following formula:
=--REPLACE(REPLACE(A1,7,0,"/"),5,0,"/")
Format it as desired.
Then you can copy paste just the value over the original.
Looking to convert the following 2015-10-07T23:59:59 into something that Excel actually recognizes as a date so I can then graph/chart with this data... I tried using datevalue and custom formatting but can't get the syntax quite right.
To get datetime from your string, you only need to replace T with space, convert to numeric and apply appropriate cell format.:
=1*SUBSTITUTE(A1,"T"," ")
I dont know if Excel can understand that type of format date, you should try to write your own custom function to get it in the format that you want.
How about yyyy-mm-ddThh:mm:ss for the custom format?
If the timestamp isn't needed, use =DATEVALUE(LEFT(A1,10)). If it is needed, then use =DATEVALUE(LEFT(A1,10))+TIMEVALUE(RIGHT(A1,8)). (Where cell A1 contains the datetime string you are trying to parse).
This will return the Julian date value (E.g. 42284 for the day, 42284.96 for day & time) which you can then apply Excel's built in date formatting to, it will also work for charts and pivot table grouping.
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.
I have a column in string format in Excel (2010) which shows "yyyy-mm-dd hh:mm:ss" and for an analysis I need it to be exactly the same, except that it is in date+time format instead of string format.
After some googling I got that macros will probably help me, but I never worked with visual basics in Excel before. On top of that, the questions I found which come close to this every time seem to have a very different solution.
I got so far that I have visual basics up to enter some code (yes yes, you may laugh at my poor skills), but I have no clue what code to enter there.
Thanks.
To get both the date and the time, use =DATEVALUE(A1)+TIMEVALUE(A1).
You don't need VBA. Use DATAVALUE function.
First try formatting the column as dates, you can use your format "yyyy-mm-dd hh:mm:ss" in the Custom Format, Type box.
If this doesn't work then create an extra column using =DATEVALUE(A1) and copy this down the column. Format it as required. You can Copy/Paste Values so that you could then replace the original column.
You can just use
=VALUE(A1)
and if Excel can interpret the string as a date, it will.
I have 100.000 rows of data in Excel. Some of the fields are dates, but the fields in Excel are as text. I need these fields in number format including both dates AND time (e.g. 21.10.2011 13:10:50). Formatting the cells doesn't work because that doesn't change the datatype. I can pick out the date and time with formulas but not get them in the same cell.
So what I am looking for is the formula to calculate the number representation of a date (the one you see if you format a date as a number).
Have you tried the =DateValue() function?
To include time value, just add the functions together:
=DateValue(A1)+TimeValue(A1)
To accomodate both data scenarios you have, you will want to use this:
datevalue(text(a2,"mm/dd/yyyy"))
That will give you the date number representation for a cell that Excel has in date, or in text datatype.
I was struggling with this for some time and after some help on a post I was able to come up with this formula =(DATEVALUE(LEFT(XX,10)))+(TIMEVALUE(MID(XX,12,5))) where XX is the cell in reference.
I've come across many other forums with people asking the same thing and this, to me, seems to be the simplest answer. What this will do is return text that is copied in from this format 2014/11/20 11:53 EST and turn it in to a Date/Time format so it can be sorted oldest to newest. It works with short date/long date and if you want the time just format the cell to display time and it will show. Hope this helps anyone who goes searching around like I did.
The best solution is using DATE() function and extracting yy, mm, and dd from the string with RIGHT(), MID() and LEFT() functions, the final will be some DATE(LEFT(),MID(),RIGHT()), details here