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
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]2019-06-27T16:05-0400[/TD]
[/TR]
[TR]
[TD]2019-06-27T16:10-0400[/TD]
[/TR]
[TR]
[TD]2019-06-27T16:35-0400[/TD]
[/TR]
</tbody>[/TABLE]

Target:
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]16:05[/TD]
[/TR]
[TR]
[TD]16:10[/TD]
[/TR]
[TR]
[TD]16:35[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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