Changing Military time to standard time

datadummy

Active Member
Joined
Mar 16, 2017
Messages
313
Office Version
  1. 365
Platform
  1. Windows
I am attempting to change military time to standard time but am having issues when the time starts with a 0, for example 0327 is changing to 8:07 AM rather than 3:27 AM. Here is the current formula I have used, =TIMEVALUE(LEFT(G2,2)&":"&MID(G2,3,2)&":"&RIGHT(G2,2)). Any thoughts on how to achieve this without using VBA?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this:

<b>Sheet</b><br /><br /><table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:80px;" /><col style="width:80px;" /><col style="width:103px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >G</td><td >H</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td > </td><td >Militar</td><td >Standard</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td > </td><td style="text-align:right; ">327</td><td style="text-align:right; ">03:27:00 a.m.</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td > </td><td style="text-align:right; ">1028</td><td style="text-align:right; ">10:28:00 a.m.</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td > </td><td style="text-align:right; ">1516</td><td style="text-align:right; ">03:16:00 p.m.</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td > </td><td style="text-align:right; ">32115</td><td style="text-align:right; ">03:11:15 a.m.</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td > </td><td style="text-align:right; ">131816</td><td style="text-align:right; ">01:18:16 p.m.</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td > </td><td style="text-align:right; ">1816451</td><td >It is not an hour</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td > </td><td style="text-align:right; ">12</td><td >It is not an hour</td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b>Formula</b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Formula</td></tr><tr><td >H2</td><td >=IF(LEN(G2)=6,TIMEVALUE(LEFT(G2,2)&":"&MID(G2,3,2)&":"&RIGHT(G2,2)),IF(LEN(G2)=5,TIMEVALUE(LEFT(G2,1)&":"&MID(G2,3,2)&":"&RIGHT(G2,2)),IF(LEN(G2)=4,TIMEVALUE(LEFT(G2,2)&":"&MID(G2,3,2)),IF(LEN(G2)=3,TIMEVALUE(LEFT(G2,1)&":"&MID(G2,2,2)),"It is not an hour"))))</td></tr></table></td></tr></table> <br /><br />
 
Upvote 0
Try this:

Sheet

AGH
MilitarStandard
It is not an hour
It is not an hour

<colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 80px;"><col style="width: 80px;"><col style="width: 103px;"></colgroup><tbody>
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]1[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]2[/TD]

[TD="align: right"]327[/TD]
[TD="align: right"]03:27:00 a.m.[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]3[/TD]

[TD="align: right"]1028[/TD]
[TD="align: right"]10:28:00 a.m.[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]4[/TD]

[TD="align: right"]1516[/TD]
[TD="align: right"]03:16:00 p.m.[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]5[/TD]

[TD="align: right"]32115[/TD]
[TD="align: right"]03:11:15 a.m.[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]6[/TD]

[TD="align: right"]131816[/TD]
[TD="align: right"]01:18:16 p.m.[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]7[/TD]

[TD="align: right"]1816451[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]8[/TD]

[TD="align: right"]12[/TD]

</tbody>

Formula
CellFormula
H2=IF(LEN(G2)=6,TIMEVALUE(LEFT(G2,2)&":"&MID(G2,3,2)&":"&RIGHT(G2,2)),IF(LEN(G2)=5,TIMEVALUE(LEFT(G2,1)&":"&MID(G2,3,2)&":"&RIGHT(G2,2)),IF(LEN(G2)=4,TIMEVALUE(LEFT(G2,2)&":"&MID(G2,3,2)),IF(LEN(G2)=3,TIMEVALUE(LEFT(G2,1)&":"&MID(G2,2,2)),"It is not an hour"))))

<tbody>
</tbody>

<tbody>
</tbody>

That was amazing it worked like a charm!! Follow up question, how would you address a cell that is labeled 0035 or 0022? Is there a way to make those show as 12:35 and 12:22?
 
Upvote 0
Another way, perhaps:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
Military
[/td][td="bgcolor:#F3F3F3"]
Standard
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]
12​
[/td][td]
12:12 AM​
[/td][td]B2: =--TEXT(A2, "0\:00")[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]
327​
[/td][td]
3:27 AM​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]
1028​
[/td][td]
10:28 AM​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]
1516​
[/td][td]
3:16 PM​
[/td][td][/td][/tr]
[/table]
 
Upvote 0
That was amazing it worked like a charm!! Follow up question, how would you address a cell that is labeled 0035 or 0022? Is there a way to make those show as 12:35 and 12:22?

You're welcome & thanks for the feedback.

Try:

=SI(LARGO(G2)=6,HORANUMERO(IZQUIERDA(G2,2)&":"&EXTRAE(G2,3,2)&":"&DERECHA(G2,2)),SI(LARGO(G2)=5,HORANUMERO(IZQUIERDA(G2,1)&":"&EXTRAE(G2,3,2)&":"&DERECHA(G2,2)),SI(LARGO(G2)=4,HORANUMERO(IZQUIERDA(G2,2)&":"&EXTRAE(G2,3,2)),SI(LARGO(G2)=3,HORANUMERO(IZQUIERDA(G2,1)&":"&EXTRAE(G2,2,2)),SI(LARGO(G2)=2,HORANUMERO("12:"&G2),"It is not an hour")))))
 
Upvote 0

Forum statistics

Threads
1,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

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