# Convert 6 numeric (military time) to standard time?

Page 1 of 1

## 1 Replies - 22486 Views - Last Post: 06 October 2007 - 08:49 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=34641&amp;s=d33a80069e44bb5407deaa93f32b3ca7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mlee

Reputation: 0
• Posts: 1
• Joined: 04-October 07

# Convert 6 numeric (military time) to standard time?

Posted 04 October 2007 - 10:45 AM

I am reading a database from an IBM I-series (AS/400 and no jokes please). The field in the database is a "time" field and is 6 numeric with 0 decimals. It is in military time (also called 24-hour time) in the form of:

183712

That is military time format for 6:37 PM and 12 seconds (6:37:12 PM)

Is there a way in VB.NET that I can convert this numeric field from military to standard time so that I would end up with:

6:37 PM ???

Thank you and please forgive my newbie-ness. I'm working at it though!

Is This A Good Question/Topic? 0

## Replies To: Convert 6 numeric (military time) to standard time?

### #2 orcasquall

Reputation: 12
• Posts: 158
• Joined: 14-September 07

## Re: Convert 6 numeric (military time) to standard time?

Posted 06 October 2007 - 08:49 PM

Try converting the time numeral into a string like
```Dim sTime As String = "183712"

```

I don't know how you retrieve and store the time numeral immediately after you get it from the database. Just convert it to string.

Then do this
```Dim dt As DateTime
dt = DateTime.ParseExact(sTime, "HHmmss", Nothing)
Dim sTheTimeFormatYouWant As String = String.Empty
sTheTimeFormatYouWant = dt.ToString("h:mm tt")

```

The ParseExact() function will then take your time string and change it into a DateTime type. (The day, month and year will be that day when it's run, as in DateTime.Now or DateTime.Today) You might want to enclose the ParseExact() in a Try-Catch clause in case your time numeral is incorrect and the parsing fails.

"HH" represents the zero-padded 24-hour hour