convert from text to date format in excel - excel

I have 2 text as below want to convert to date in excel
2/10/2001 4:00:00 AM
2/10/2001 12:30:00 PM
I tried =DATEVALUE() and TEXT(A1, "mm/dd/yyyy hh:mm") in excel which returns me error
I also tried to calculate these 2 dates which also return me error

Try below formula
=TEXT(--LEFT(A1,SEARCH(" ",A1)-1)+(--MID(A1,SEARCH(" ",A1)+1,100)),"mm/dd/yyyy hh:mm:ss AM/PM")
This simple formula should also work- format the resulting cell as mm/dd/e hh:mm:ss AM/PM
=TRIM(DATEVALUE(A1))+TRIM(TIMEVALUE(A1))
FILTERXML() will also work.
=TEXT(SUM(FILTERXML("<t><s>"&SUBSTITUTE(TRIM(A1)," ","</s><s>")&"</s></t>","//s[position()<3]")),"mm/dd/e hh:mm:ss AM/PM")

I'm not sure I understand the question. When you enter those values into a spreadsheet, Excel understands them as date/time values. No conversion is necessary. You can perform date/time arithmetic on them as is.
Cell A1 & B1 show the values I copied from your question and pasted into the worksheet. C1 shows the time interval in hours.

Related

Converting MM:DD:YYYY hh:mm:ss to DD:MM:YYYY hh:mm:ss in excel

I'm trying to convert the timestamp data in Microsoft excel where the timestamp is coming asMM:DD:YYYY hh:mm:ss (12/25/2016 12:00:55 AM).this Formet doesnt support in excel and i wanted to change it to DD:MM:YYYY hh:mm:ss (25/12/2016 12:00:55 AM)
i have seached so many times but all i get is DD:MM:YYYY to MM:DD:YYYY which is not the case.
Either add a column with =MID(B2,4,3) & LEFT(B2,2) & RIGHT(B2,17) where B2 is replaced with your date value cell reference (The formula only works if all dates are in that 22 character format you used as an example).
or
write a macro to amend the values in that column.

Excel convert TEXT (28th April 2017) TO DATE

I have some dates in my excel spreadsheet that have th,nd,st and rd in the string so I am currently struggling to convert them to a date format of dd/mm/yyyy.
How would I be able to do this using a formula?
28th April 2017 = 28/04/2017
Thanks
The text being in A1:
=DATEVALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"th",""),"st",""),"nd",""),"rd",""))
With a formula:
=--(LEFT(A1,MIN(SEARCH({"th","st","nd","rd"},A1 & "thstndrd"))-1)&" " & MID(A1,MIN(SEARCH({"th","st","nd","rd"},A1 & "thstndrd"))+3,LEN(A1)))
This is an array formula and needs to be confirmed with Ctrl-Shift-Enter.
Then format as dd/mm/yyyy
You could give a try with this formula as well,
=IF(ISNUMBER(VALUE(LEFT(A1,2))),TEXT(REPLACE(A1,3,2,""),"mm/dd/yyyy"),TEXT(REPLACE(A1,2,2,""),"mm/dd/yyyy"))
The formula finds the numeric value in first two places and formats the date accordingly. The advantage of this formula is, you can modify the mm/dd/yyyy format as per your needs. There would not be a necessity to change the format of the cell.

Convert cell value to DateTime

I have a row of cells in Excel filled with datetimes in the following messy format: July 13, 2016 at 12:10AM. I want to convert this to 2016/07/13 12:10 ('yyyy/mm/dd hh:mm' in the 24h format). Can I do this using a formula or should I write a vba code for this?
Two issues:
First you must remove the at
Second you need a space between the time and the AM or PM
The follow formula will turn it into a date/time:
=--SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"at",""),"AM"," AM"),"PM"," PM")
Then you can format the cell with the custom format:
yyyy/mm/dd hh:mm

Excel 2013 date format conversion. 30 Jan, 15 18:02:05 to 30.01.2015

In MS Excel 2013 I import a CSV file, no matter if I format it using the delimined or any other option the results are the same. My date in Excel looks like: 30 Jan, 15 18:02:05 in a single cell. All I need is to convert it to a date format 30.01.2015 for example. I have a column of these and need to convert the values at once. (I tried TEXT, DATE, MID, DATEVALUE, MONTH, DATEVALUE...) but none of them are able to convert the date format. Also it does not matter if I convert it with format cells...to date it always displays the same i.e. 30 Jan, 15 18:02:05
Not sure what I am doing wrong. Getting a bit frustrating, thanks for any advice. Most of the above give a #VALUE error.
With data in A1 in B1 enter:
=DATEVALUE(LEFT(A1,FIND(" ",A1)-1) & "-" & MID(A1,FIND(" ",A1)+1,3) & "-20" & MID(A1,FIND(",",A1)+2,2))
and format B1 as dd.mm.yyyy for example:

How to concatenate date(mm/dd/yyyy) with time (hh:mm:ss) using VBA

I have two cells: A1 and B1
A1 has data in format of mm/dd/yyyy
B1 has data in format of hh:mm:ss
When I concatenate the two cells A1 and B1 using VBA, the output contains has the format mm/dd/yyyy hh:mm. Why are the seconds not displaying? How can I fix this?
Note :
a) After concatenation the output is copied to A1.
b) I tried changing the format of date to dd/mm/yyyy, in this case its working fine .
It's hard to tell what you are doing exactly without seeing your code, but I think you are specifying the format of the value you are writing to cell A1: using the VBA Format function you are converting the date-time into a string.
However, to change the way the date is displayed in a cell, you need to change the format of that cell itself (not the format of the value written to it). Otherwise Excel will likely interpret the value in the cell and snap it back to the specified number format for that cell.
You can change the cell's format in the Excel 2010 window like this: Home > Number > Custom > Type: mm/dd/yy hh:mm:ss
Or, using VBA:
Range("A1").NumberFormat = "mm/dd/yy hh:mm:ss"
Try to change the format of C1 to
mm/dd/yyyy hh:mm:ss

Resources