How to extract date from text string

Gunjiddash

New Member
Joined
Nov 2, 2020
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Im working with a dataset that has work hours in the following format (11:00 am - 8:00 pm). How can i extract the start time and end time into 2 separate columns as per the photo below? I know you can use a =MID(A2, SEARCH function but don't know how to set the parameters. Please help!

screenshot-docs-google-com-spreadsheets-d-1ACOVWw4h2s8Bc4DxAtlNRIanQSDxcE2p2XmifozKxCM-edit-16...png
 

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.
=mid(F2,find("-",F2)-9,8) for the start time
=mid(F2,find("-",F2)+1,8) for the end time
 
Upvote 0
You could also just use
Excel Formula:
=LEFT(F2,8)
=RIGHT(F2,8)
If you want to get rid of any extra spaces you could wrap them both in Trim
 
Upvote 0
You could also Select E2:Ex then use Text to Columns (on the Data ribbon tab) -> Fixed width -> Next -> Adjust dividers (double-click &/or drag) like this

1604319330316.png



-> Next -> Destination: F2 -> Click in the middle column at the bottom & choose 'Do not import column'

1604319671659.png


Finish

Result:

20 11 02.xlsm
EFG
211:00 am - 8:00 pm11:00 AM8:00 PM
311:00 am - 8:00 pm11:00 AM8:00 PM
411:00 am - 8:00 pm11:00 AM8:00 PM
Split Times
 
Upvote 0
And
Just if you like to use a VBA
VBA Code:
Sub test()
    Dim a
    Dim i
    a = Cells(2, 1).Offset(, 4).Resize(Cells(Rows.Count, 5).End(xlUp).Row - 1)
    ReDim b(1 To UBound(a))
    For i = 1 To UBound(a)
        b(i) = Split(a(i, 1), "-")
    Next
    b = Application.Transpose(Application.Transpose(b))
    Cells(2, 1).Offset(, 5).Resize(UBound(b), 2) = b
End Sub
 
Upvote 0
And
Just if you like to use a VBA
VBA Code:
Sub Test2()
  Range("E2", Range("E" & Rows.Count).End(xlUp)).TextToColumns Range("F2"), xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(8, 9), Array(11, 1))
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,647
Messages
6,126,006
Members
449,280
Latest member
Miahr

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