Solved

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

Posted on 2008-10-03
3
4,226 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 92

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 92

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now