Converting Military Time to Standard time

# Thread: Converting Military Time to Standard time

1. Senior Member
Join Date
Dec 1969
Posts
330

## Converting Military Time to Standard time

Before I go and write some big function I wanted to make sure there isn&#039;t something simple I can call to convert a 4 digit number into standard time. FormatDateTime(date,4) won&#039;t work because I&#039;m not storing a date/time, just the 4 digit military time. So I&#039;d to be able to convert 0500 to 5:00 AM. Is there some sort of convert funtion that will do this or do I need to write one myself. Thanks much for your help.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Well, you could do...

&nbsp;<BR>&#060;%<BR>milTime = CLng( milTime ) &#039; may not be needed; can&#039;t hurt<BR><BR>stdTime = TimeSerial( milTime 100, milTime MOD 100, 0 )<BR>%&#062;<BR><BR>But then, when you go to display that, such as via<BR> &#060;%= FormatDateTime( stdTime, vbLongTime ) %&#062;<BR>you are going to always get ":00" tacked on for the seconds.<BR><BR>If that&#039;s okay, the you are home free. If you don&#039;t want the seconds, you *could* do<BR> &#060;%= Replace( FormatDateTime( stdTime, vbLongTime ), ":00 ", " " %&#062;<BR><BR>But between the two conversions you now have enough code that it would probably be better to just write your own function:<BR><BR>&#060;%<BR>Function StdTimeFromMilTime( milTime )<BR> milTime = CLng( milTime ) &#039; in case a string was passed in<BR> hr = milTime 100 &#039; yes, that *IS* a backslash<BR> mn = milTime MOD 100<BR> If hr &#062; 12 Then <BR> hr = hr - 12<BR> ampm = " PM"<BR> Else<BR> ampm = " AM"<BR> If hr = 0 Then hr = 12<BR> End If<BR> StdTimeFromMilTime = hr & ":" & Right( "0" & mn, 2 ) & ampm<BR>End Function<BR>%&#062;<BR><BR>&#060;SHRUG&#062; Your choice &#060;/SHRUG&#062;<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
330

## THANKS Bill

...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•