Solved

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

Posted on 2004-10-14
10
434 Views
Last Modified: 2010-05-18
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
Comment
Question by:sticar
  • 5
  • 3
  • 2
10 Comments
 
LVL 1

Expert Comment

by:VBtorment
ID: 12311732
Format$(CDate(strTime),"h:mm")
0
 

Author Comment

by:sticar
ID: 12311770
Hmm... still says 2:00
0
 
LVL 1

Assisted Solution

by:VBtorment
VBtorment earned 100 total points
ID: 12312493
oops my mistake :)

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

capitalize it :)
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:sticar
ID: 12312589
Ahhh... much better.  Any idea why it would show:
14:01 instead of 14:00?
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12312684
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
 
LVL 10

Accepted Solution

by:
Hans Langer earned 150 total points
ID: 12312694
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
 

Author Comment

by:sticar
ID: 12312737
I'm only formating a string.

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

Comes out "13:00"
0
 

Author Comment

by:sticar
ID: 12312741
Oops,
Comes out "13:01", suppose to be "13:00"
0
 

Author Comment

by:sticar
ID: 12312932
Ahhh... I just noticed it's a lowercase "mm".... THANKS!!!!
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12312944
Format(CDate("1:00 PM"), "HH:mm")
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 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