# Thread: Military to Standard Time

1. ## Military to Standard Time

I've spent wayyyyyyyyyyyyyyyy too much time on this.

I need to convert military time to standard time as follows:

1730 -> 5:30a

My convoluted code that works in the expression builder, but not in the update operation is the following.

What am I doing wrong? Remember this is in A5V4.5

Thanks

Tom

2. ## Re: Military to Standard Time

Tom, does your military time always include 4 digits and no colon? i.e. 0230 for 2:30 am?

I don't remember that A5v4 supports a "time" data type. So when you say "standard time", you're really talking only about a character data type field, right?

3. ## Re: Military to Standard Time

Good Morning Tom

Originally Posted by Tom Cone Jr
Tom, does your military time always include 4 digits and no colon? i.e. 0230 for 2:30 am?

I don't remember that A5v4 supports a "time" data type. So when you say "standard time", you're really talking only about a character data type field, right?
Correct no colon and should be 4 characters, but I don't force it.

Yes, the field is 6 characters wide. Hence the "a" or "p" to squeeze "12:30 pm" into 12:30p

Thanks for taking a look.

Tom

4. ## Re: Military to Standard Time

If you force military time to always have 4 digits you can do this, but I'm not sure it's any easier to maintain.

Code:
```m_time = "1630"
dim s_time as c
s_time = if(val(left(m_time,2))< 12, left(m_time,2) + ":" + right(m_time,2) + "a", if(val(left(m_time,2)) = 12,  left(m_time,2) + ":" + right(m_time,2) + "p", ltrim(str(val(left(m_time,2)) - 12)) + ":" + right(m_time,2) + "p"))
?s_time
= "4:30p"```

5. ## Re: Military to Standard Time

Tom,

It doesn't work in the update operation. It leaves the minutes blank, but does add the "p" or "a"

Code:
dim s_time as c
dim m_time as C
m_time="1730"
s_time = if(val(left(m_time,2))< 12, left(m_time,2) + ":" + right(m_time,2) + "a", if(val(left(m_time,2)) = 12, left(m_time,2) + ":" + right(m_time,2) + "p", ltrim(str(val(left(m_time,2)) - 12)) + ":" + right(m_time,2) + "p"))
?s_time
= ""

The above code in the expression builder works fine, but in the interactive window it results in ""

????

Tom

6. ## Re: Military to Standard Time

If your field width for military time is more than 4, it's likely the

right(m_time,2)

is simply supplying blanks, since the trailing blanks are the last two chars stored in the field

My example assumes a width of 4, with all places filled.

7. ## Re: Military to Standard Time

YEsssssssssssssssssssss!!

There is a Santa Clause and I got my present early!

Tom - Thank you very much.

#### Posting Permissions

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