Text String to Date Time Conversion in Excel - excel

I am kind of struggling with dates in Excel. So, here is the case:
I have dates in Column AP in text format as I imported the same from a CSV. All the dates are suppose be DD-MM-YYYY HH:MM:SS.
Using the formula =DATEVALUE(TEXT(AP2,"DD-MM-YYYY")) + TIMEVALUE (TEXT(AP2,"HH:MM:SS")) I have been able to convert most of the dates. However, for certain dates like "13-06-2018 00:08:42" or "15-06-2018 00:10:11", the mentioned formula doesn't work. I am getting #VALUE!
Need help.. Thanks..

Since you're getting #VALUE! when the first field is greater than 12, I surmise that your formula is mixing up the month and date fields. One brute-force way to get the dates is:
=DATE(MID(AP2,7,4),MID(AP2,4,2),MID(AP2,1,2))+TIME(MID(AP2,12,2),MID(AP2,15,2),MID(AP2,18,2))
Hope that helps

Related

Date incorrectly converts into required format (dd/mm/yy) in excel

Hi I know lots of similar questions can be found here, but I am still facing this problem:
I have a table with one column called Dates with some values shown below:
12/2/2021
11/2/2021
10/2/2021
9/2/2021
8/2/2021
7/2/2021
6/2/2021
5/2/2021
4/2/2021
3/2/2021
2/2/2021
1/2/2021
31/01/21
30/01/21
When I try to convert it using Format cells either by selecting category as Date or adding custom category as dd/mm/yy, excel treat the dd/mm/YYYY values as mm/dd/yy.
So for example, instead of treating 1st row as 12 February, excel thinks of it as 2 December.
I also tried convert text to columns by going to DATA and setting it as DMY but it doesn't solve the problem.
Any help is really appreciated.
Try this formula:
= DATE( YEAR(A1), DAY(A1), MONTH(A1) )
If the values have any space character, try this one:
= DATE( YEAR(TRIM(A1)), DAY(TRIM(A1)), MONTH(TRIM(A1)) )
Assumptions:
All the dates were originally DMY
Your windows regional settings short date format is MDY
You will need to convert to a proper date
If the value is text, then it will be in DMY format and you can extract the sections and convert to a date
If the value is numeric, then it has been converted improperly and you need to reverse the month and day part
Given those assumptions, the following formula should work.
I am using the LET and FILTERXML functions which are available in Excel Office 365 Windows versions.
If you don't have that version of Excel, you can still do this with formulas but it will be more complex. Or you can use VBA.
=IFERROR(DATE(YEAR(A1),DAY(A1),MONTH(A1)),
LET(x,FILTERXML("<t><s>" & SUBSTITUTE(A1,"/","</s><s>")& "</s></t>","//s"),
DATE(INDEX(x,3)+IF(INDEX(x,3)<30,2000),INDEX(x,2),INDEX(x,1))))

Can't use HOUR() because Excel doesn't recognize a time

Excel doesn't recognize a time column so I'm unable to parse the hour from it using =HOUR().
I've tried formatting the column of datetimes (formatted dd/mm/yyyy HH:MM) as date and time using Excel formatting, and also tried pulling the datevalue using =DATEVALUE(), but always end up with a #VALUE! error.
time hour ("=HOUR(A2)")
29/05/2018 16:20 #VALUE!
29/05/2018 16:25 #VALUE!
29/05/2018 16:30 #VALUE!
I would expect if the cells are formatted properly then the hour (16) should be returned, but instead it is just the #VALUE! error, so there must be some formatting issue, but I can't figure out what it is or how to fix it.
Your values are Text rather than true date/times. Use:
=--MID(A1,12,2)
instead:
In the event you have 8:10 instead of 08:10, you can use this to capture just the hour:
=--TRIM(MID(A1,SEARCH(" ",A1),SEARCH(":",A1)-SEARCH(" ",A1)))
Your values are text, and it is likely that your windows regional settings are MDY.
Best solution:
Go back to the source and convert properly when importing into Excel. Especially if you are importing a text or csv file.
Possible solution if ALL of your values are text:
Use Data Text-toColumns wizard.
Split between the date and the time
For the date column, select DMY for the format
If some of the values are text, and others real dates, then you will have to convert the text values to dates first, and not alter the real date values. Best way: see "best" solution, but we'd need more information.

Convert General to Date in Excel

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.

How to reverse number orders in Excel to formate a date?

I'm searching without success for solution to this problem, as mentioned in title.
The following:
I have many cells with numbers, like: 20170510
This is actually a date: 10th of May 2017
Now my question, how can I bring this number in the proper form to build the right date like: 05/10/2017? So that Excel recognizes it as a date.
Any help would be really appreciated.
Assuming your date string is in A2, then try this...
=DATE(LEFT(A2,4),MID(A2,5,2),RIGHT(A2,2))
For a column of such numbers choose Text to Columns with Tab as delimiter and Date format YMD.
A much simpler formula for you to try,
=TEXT(TEXT(A1,"0000-00-00"),"mm/dd/yyyy")
The advantage of this formula is, you can change the mm/dd/yyyy format to any other format of your choice and it would work.
dd-mmm-yy , dd/mm/yyyy etc...

Converting a string to a date in a cell

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

Resources