Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBS Convert Time hh:mm:ss (1:23:58 PM) to HH:mm:ss (13:23:58)

Posted on 2008-10-03
3
Medium Priority
?
5,601 Views
Last Modified: 2012-08-13
How do convert  a time hh:mm:ss (1:23:58 PM) to Military time HH:mm:ss (13:23:58) in vbscript
I know that FormatDateTime will do a 24-hour format using vbShortTime but I need to keep the seconds at the end.  Here is an example using vb function FormatDateTime

Dim Time
Dim FTime

FTime = FormatDateTime(Time, 4)

But this cuts of the seconds and I need the seconds

Please HELP!
0
Comment
Question by:kuney
  • 2
3 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 22636439
FTime = Right("0" & Hour(Time), 2) & ":" & Right("0" & Minute(Time), 2) & ":" & Right("0" & Minute(Time), 2)
0
 

Accepted Solution

by:
kuney earned 0 total points
ID: 22637208
FTime = Right("0" & Hour(Time), 2) & ":" & Right("0" & Minute(Time), 2) & ":" & Right("0" & Minute(Time), 2)
The last Minute needs to be changed to Second
But this doesn't change the time to Military time

But I could Dim another variable and use this after the FormatDateTime vbShortTime so it would look like this:

Time = 1:23:58

Dim Time
Dim FTime
Dim MTime

MTime = FormatDateTime(Time, 4)
FTime = Right("0" & Hour(MTime), 2) & ":" & Right("0" & Minute(MTime), 2) & ":" & Right("0" & Second(Time), 2)

Now FTime should equal 13:23:58

Would this be the way others would go about changing 1:23:58 to 13:23:58
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 22652274
kuney,

Get rid of your variable Time; there is already a Time function that returns the current system time, shorn of
its date portion.  My code suggestion assumes you are using the Time function, and *not* your variable Time.

Regards,

Patrick
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question