"1:00 PM" or "1:00 AM" to change to military time?

How do I change the AM or PM to military time?

strMytime = "2:00 PM"

strNewTime = Format(CDate(strMytime), "hh:mm")      ' this only changes it to 2:00 not 14:00

THANKS
sticarAsked:
Who is Participating?
 
Hans LangerConnect With a Mentor Commented:
Upss..
Dim MyDateTime As Date = #1/27/2001 5:04:23 PM#
MyStr = Format(MyDateTime, "hh:mm:ss tt")   ' Returns "05:04:23 PM".
MyStr = Format(MyDateTime, "HH:mm:ss")   ' Returns "17:04:23"

0
 
VBtormentCommented:
Format$(CDate(strTime),"h:mm")
0
 
sticarAuthor Commented:
Hmm... still says 2:00
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
VBtormentConnect With a Mentor Commented:
oops my mistake :)

Format$(CDate(strTime),"HH:MM")

capitalize it :)
0
 
sticarAuthor Commented:
Ahhh... much better.  Any idea why it would show:
14:01 instead of 14:00?
0
 
Hans LangerCommented:
NameSpace Microsoft.VisualBasic

MyStr = Format(MyDateTime, "hh:mm:ss tt")   ' Returns "05:04:23 PM".
MyStr = Format(MyDateTime, "HH:mm:ss")   ' Returns "17:04:23"

GL
0
 
sticarAuthor Commented:
I'm only formating a string.

Dim strMyTime As String = Format(CDate("1:00 PM"),"HH:MM"))

Comes out "13:00"
0
 
sticarAuthor Commented:
Oops,
Comes out "13:01", suppose to be "13:00"
0
 
sticarAuthor Commented:
Ahhh... I just noticed it's a lowercase "mm".... THANKS!!!!
0
 
Hans LangerCommented:
Format(CDate("1:00 PM"), "HH:mm")
0
All Courses

From novice to tech pro — start learning today.