Converting text to date

pmich

Active Member
Joined
Jun 25, 2013
Messages
294
etaf
In my file I have many rows in Col A with date and Time format. I want to convert to date in Col C.
In my file [Nov 2, 2019 8:10:20 AM] was in A2.
I used [=MID(A2,1,12)] in B2 and got [Nov 2, 2019] in B2.
As per your suggestion I used [=VALUE(RIGHT(B2, 16))[ and got [43776] in C2.
I did format C2 as [DATE] and chose [14-Mar-2001] [Eng (US)] and got [2-Nov-2019].
A. Am I doing right or should I do something else to make it easier?
B. Kindly suggest me how to use in vba.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
instead of using 3 coloumns
=value(MID(A2,1,12))
and format
i dont know vba
 
Upvote 0
If the data you have in column A are actual dates formatted as text, i.e. the underlying value is a date value and not text, then you can use the Int formula to get rid of the time portion of the date. Date/Time values are really just numbers. The date portion is the whole number and the time is represented by the decimal portion.

Book1
AB
1November, 2 2019 8:10 AM11/2/2019
Sheet2
Cell Formulas
RangeFormula
B1B1=INT(A1)
 
Upvote 0
an alternative solution is to use Power Query/Get and Transform. Here is the Mcode

VBA Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type datetime}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Column1", type date}})
in
    #"Changed Type1"
 
Upvote 0
If it is purely text, Power Query can convert it pretty easily too.

Book1
ABC
1RawRaw
2Nov 2, 2019 8:10:20 AM11/2/2019
Sheet3


VBA Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    textToDateTime = Table.TransformColumnTypes(Source,{{"Raw", type datetime}}),
    dateTimeToDate = Table.TransformColumnTypes(textToDateTime,{{"Raw", type date}})
in
    dateTimeToDate
 
Upvote 0

Forum statistics

Threads
1,215,452
Messages
6,124,916
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top