Best way to convert a text string containing date and time into Excel date and times?

helpneeded2

Board Regular
Joined
Jun 25, 2021
Messages
110
Office Version
  1. 365
Platform
  1. Windows
The data I am drawing from formats the date and time in a single text value:

10/1/2021 5:00:00 PM

I wish to have a column on my sheet to show the date, and a separate one to show the time. The tricky part, is that as show in the example below, the month may consist of 1 or 2 characters, and the date also similarly will show the hours in 1 or 2 characters. While I am working on a very long formula to try to accomplish this I'm thinking there has to be a much easier way. What would be the easiest way to split the time and date apart and then convert them into a date() and time() value?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Here is the formula I am currently using to get the date:
=IF('RAW DATA'!A2="","",DATE(RIGHT(TRIM(LEFT('RAW DATA'!A2,10)),4),IF(MID('RAW DATA'!A2,5,1)="/",MID('RAW DATA'!A2,4,1),MID('RAW DATA'!A2,4,2)),IF(MID('RAW DATA'!A2,2,1)="/",LEFT('RAW DATA'!A2,1),LEFT('RAW DATA'!A2,2))))
 
Upvote 0
I really wish I could edit my prior posts. Here is the working formula for above (I had the month and day switched):

=IF('RAW DATA'!A2="","",DATE(RIGHT(TRIM(LEFT('RAW DATA'!A2,10)),4),IF(MID('RAW DATA'!A2,2,1)="/",LEFT('RAW DATA'!A2,1),LEFT('RAW DATA'!A2,2)),IF(MID('RAW DATA'!A2,5,1)="/",MID('RAW DATA'!A2,4,1),MID('RAW DATA'!A2,4,2))))

Surely there is a better way of doing this?
 
Upvote 0
Actually I now realize that won't work as I didn't take into account that both the day and the month might be 1 or 2 characters.
 
Upvote 0
Unless there are hidden characters in the date string that prevent a formula from reading it properly,
Date
Excel Formula:
=INT(A2)
Time
Excel Formula:
=MOD(A2,1)
You will need to format the formula cells as required.
 
Upvote 0
The below would also work
Excel Formula:
=DATEVALUE(A1)
and
Excel Formula:
=TIMEVALUE(A1)
 
Upvote 0
Then you have more characters in that text string
Book1
ABC
110/1/2021 5:00:00 PM10-1-202117:00:00
Sheet1
Cell Formulas
RangeFormula
B1B1=DATEVALUE(A1)
C1C1=TIMEVALUE(A1)
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,772
Members
449,049
Latest member
greyangel23

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