How to Format time in

Posted on 2005-04-15
Last Modified: 2008-02-07
I read the date and time value from the array as:
"15-APR-2005 01:00:00 PM"

I want to grab only time and if it is PM then I want to format for 1:00:00 PM as: 1300,1400,1500 and so on...,
else if it is AM then for 1:00:00 AM I want to format as 100,200,300... and so on.

Question by:vmandem
    LVL 2

    Expert Comment

    Assuming you are using a DateTime object, you can do something like the following:

    Dim CurrentTime as DateTime
    Dim CurrentMilitaryTime as String
    CurrentTime = DateTime.Now

    CurrentMilitaryTime = CurrentTime .Hour.ToString() & CurrentTime.Minute.ToString()

    the Hour member will return a hour between 0 - 23
    So, this
    LVL 12

    Accepted Solution


    Dim CurrentTime as DateTime
    Dim sCurrentTime as String
    CurrentTime = DateTime.Now

    sCurrentTime = CurrentTime.ToString("H:mm")  ' if you want the colon


    sCurrentTime = CurrentTime.ToString("Hmm")  ' if you don't want the colon

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, 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, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 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

    19 Experts available now in Live!

    Get 1:1 Help Now