Need help in Timestamp format conversion

moramramesh

New Member
Joined
May 22, 2019
Messages
17
I have timestamp under Column A in this format: 2019-06-27T16:05-0400. I want only 16:05 from that timestamp i.e. hh:mm. Can someone help how we can do using macro?

Source
2019-06-27T16:05-0400
2019-06-27T16:10-0400
2019-06-27T16:35-0400

<tbody>
</tbody>

Target:
16:05
16:10
16:35

<tbody>
</tbody>
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hey moramramesh,

select your cell , right click, format cells, custom, select hh:mm
 
Last edited:
Upvote 0
How about
Code:
Sub moramramesh()
   With Range("A1", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if(isnumber(search(""t"",@)),mid(@,search(""t"",@)+1,5)+0)", "@", .Address))
      .NumberFormat = "hh:mm"
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
How about
Code:
Sub moramramesh()
   With Range("A1", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("[B][COLOR="#0000FF"]if(isnumber(search(""t"",@))[/COLOR][/B],mid(@,[B][COLOR="#FF0000"]search(""t"",@)+1[/COLOR][/B],5)+0)", "@", .Address))
      .NumberFormat = "hh:mm"
   End With
End Sub
The text appears to be of consistent structure and length so I think you can replace what I show in red above with the number 12. Also, since you are starting with cell A1, do you really need to test if there is a "t" in the cell values (especially since you do not provide a value if FALSE)?
 
Last edited:
Upvote 0
I think this macro should also work...
Code:
Sub moramramesh2()
  [A:A].Replace "*t", "", xlPart, , False, , False, False
  [A:A].Replace "-*", "", xlPart
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,460
Members
448,965
Latest member
grijken

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