[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

"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
0
sticar
Asked:
sticar
  • 5
  • 3
  • 2
2 Solutions
 
VBtormentCommented:
Format$(CDate(strTime),"h:mm")
0
 
sticarAuthor Commented:
Hmm... still says 2:00
0
 
VBtormentCommented:
oops my mistake :)

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

capitalize it :)
0
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!

 
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
 
Hans LangerCommented:
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
 
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now