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,370 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

12 Experts available now in Live!

Get 1:1 Help Now