Convert time to military time?

R

Robert Crandal

How can I convert the current time into military time?
I'd like to show the results in a message box kind of
like:

MsgBox "The military time is: " & strMilitaryTime

The variable strMilitaryTime is a string variable which
is where I want to store the current military time. Oh
ya, I want the military time format to be: "hh:mm:ss",
so 3:42:11 PM should convert to 15:42:11, etc...

Thank you!

Robert Crandal.
 
R

Rick Rothstein

You didn't say where the 3:42:11 PM time came from. I'll take a guess at a
TextBox so I think you would be looking for this...

If IsDate(TextBox1.Value) Then
strMilitaryTime = Format(TextBox1.Value, "hh:mm:ss")
MsgBox "The military time is: " & strMilitaryTime
End If

Rick Rothstein (MVP - Excel)




"Robert Crandal" wrote in message

How can I convert the current time into military time?
I'd like to show the results in a message box kind of
like:

MsgBox "The military time is: " & strMilitaryTime

The variable strMilitaryTime is a string variable which
is where I want to store the current military time. Oh
ya, I want the military time format to be: "hh:mm:ss",
so 3:42:11 PM should convert to 15:42:11, etc...

Thank you!

Robert Crandal.
 
R

Rick Rothstein

Actually, maybe I should fill out that If..Then block...

If IsDate(TextBox1.Value) Then
strMilitaryTime = Format(TextBox1.Value, "hh:mm:ss")
MsgBox "The military time is: " & strMilitaryTime
Else
MsgBox "That is not a correct time value!"
End If

Rick Rothstein (MVP - Excel)




"Rick Rothstein" wrote in message
You didn't say where the 3:42:11 PM time came from. I'll take a guess at a
TextBox so I think you would be looking for this...

If IsDate(TextBox1.Value) Then
strMilitaryTime = Format(TextBox1.Value, "hh:mm:ss")
MsgBox "The military time is: " & strMilitaryTime
End If

Rick Rothstein (MVP - Excel)




"Robert Crandal" wrote in message

How can I convert the current time into military time?
I'd like to show the results in a message box kind of
like:

MsgBox "The military time is: " & strMilitaryTime

The variable strMilitaryTime is a string variable which
is where I want to store the current military time. Oh
ya, I want the military time format to be: "hh:mm:ss",
so 3:42:11 PM should convert to 15:42:11, etc...

Thank you!

Robert Crandal.
 
R

Robert Crandal

Thank you Rick, your code was sufficient enough for
my needs. It was simpler than I expected, because I saw
other examples online that involved modulus arithmetic.

And BTW, I was actually getting the current time from
the "Time" variable (I think).

Thanks again.

----- Original Message -----
From: "Rick Rothstein" <[email protected]>
Newsgroups: microsoft.public.excel.programming
Sent: Monday, April 11, 2011 1:18 AM
Subject: Re: Convert time to military time?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top