Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert regular time to military time or vice versa 1

Status
Not open for further replies.

H1004

MIS
Oct 28, 2003
136
US
The situation is this.. I have two fields. One is in regular time & another is in military time
For example:
4:35 regular
16:56 military
So how can I convert one or the other into regular or military time.
I need for it to be consistent in order for me to do computation like subtracting them to find the difference
 
If the data type of your fields is DateTime then no conversion is necessary. Military or conventional time is only a presentation issue ... not a storage issue. All DateTime values are stored as Doubles with the Date preceding the decimal place and the Time following it. If you display a DateTime field with
[tt]
Format (myDateTime, "hh:nn:ss" )
[/tt]

Then you will get 24-hour (i.e. Military) time. If you use
[tt]
Format (myDateTime, "hh:nn:ss AMPM" )
[/tt]

then it is conventional time BUT the internal storage of the DateTime value is unchanged.
 
I did that the following to reformat the field, but it comes out as 00:00 for all the record

CompTime: Format([MilCompTime],"Short Time")

Another thing: If I were to get this working, would it take care of the problem with subtracting time.
Thank you
 
Again ... two separate issues. Your reformating using the Format statement results in a text string ... not a time. The results that you get from that are dependent on how your locale settings have defined "short time".

When you want to do computations you should work with the field values and not their formatted text equivalents. For example
[blue][tt]
DateDiff ("n", myTime1, myTime2 )
[/tt][/blue]
will give you the number of minutes between "myTime1" and "myTime2" without regard to how they may be formatted.

Just as an experiment, change your specification to
[blue][tt]
CompTime: MilCompTime
[/tt][/blue]
and let Access format the field. You may be getting "00:00" because these are date fields that have no time component (i.e. the part after the decimal is zero.)
 
I think I might have confused you. Right now, I'm working with two fields that orginally format as Number(Long Integer). I've successfully manipulate these two fields into military time now meaning it's straight out number & not in any short or long time format.
Example

Order Time: 1256
Complete Time: 1425

My problem is that I need to do computation between this two fields to find out how much time it took to complete this task from order time to complete time.
If I do straight out substraction, it's not right for time because there's only 60 minutes in an hour and not 99. So I figure if I convert them into short time and then do computation, then it would work.

Basically, I'm not sure if this is the right way to do it. Unless you know of a better way. Please advise
thank you,
 
OK. I infer that your integer value "1256" for example equates to a timestamp of "12:56" and similarly "1425" is "14:25". If so then
[blue][tt]
Dim OrderTime As Date
Dim CompleteTime As Date
Dim ElapsedTime As Long
OrderTime = TimeSerial ( 1256\100, 1256-(100 * (1256\100)), 0)
CompleteTime = TimeSerial ( 1425\100, 1425-(100 * (1425\100)), 0)
ElapsedTime = DateDiff ( "n", OrderTime, CompleteTime )
[/tt][/blue]
Should give you what you require.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top