convert text to real time value

President

Board Regular
Joined
Aug 27, 2014
Messages
130
hello

i have data in my cells like this


11Pm-2AM
2AM-5AM
9PM-12AM


i want this to be recognized as recognizable time in excel
i want this to be converted like this

11:00 PM in A2 and 2:00 AM in B2








<tbody>
</tbody>
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
With data in cell A1

From time
=TIME(SUBSTITUTE(SUBSTITUTE(UPPER(LEFT(A1,FIND("-",A1)-1)),"AM",""),"PM","")+IF(RIGHT(LEFT(A1,FIND("-",A1)-1),2)="PM",1,0)*12,0,0)

To Time
=TIME(SUBSTITUTE(SUBSTITUTE(UPPER(RIGHT(A1,LEN(A1)-FIND("-",A1))),"AM",""),"PM","")+IF(RIGHT(RIGHT(A1,LEN(A1)-FIND("-",A1)),2)="PM",1,0)*12,0,0)


UPDATE: 12AM in the last example returns 12PM :(
00AM returns 12AM
 
Upvote 0
hours only

Another possible option (the cells containing the formula would need to be formatted as time).


Excel 2012
ABC
111PM-2AM23:00:0002:00:00
22AM-5AM02:00:0005:00:00
39PM-12AM21:00:0000:00:00
Sheet1
Cell Formulas
RangeFormula
B1=SUBSTITUTE(SUBSTITUTE(UPPER(LEFT($A1,FIND("-",$A1)-1)),"PM",":00 PM"),"AM",":00 AM")+0
C1=SUBSTITUTE(SUBSTITUTE(UPPER(MID($A1,FIND("-",$A1)+1,99)),"PM",":00 PM"),"AM",":00 AM")+0
 
Upvote 0
Special KK99
thank you very much it worked.

wow, i did not expect it would require this sophistication

thanks FormR
your formula also worked.

i saved them in my favrourate.
 
Upvote 0

Forum statistics

Threads
1,207,256
Messages
6,077,317
Members
446,278
Latest member
hoangquan2310

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