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,770 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

734 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