Time Display 00:00

Posted on 2007-07-22
Last Modified: 2010-04-23
Hi Experts

I have a datetime picker which activates on a textbox click event.
How do I get it to display a time of 00:00 when it appears if the textbox is blank or the time as set in the textbox if its not blank. In

Question by:JoeBo747
    LVL 18

    Accepted Solution

    DateTimePciker.Format = Custom, DateTimePciker.CustomFormat = HH:mm

    Place this code in form load event

    if textBox1.Text = "" then
        dateTimePicker1.Value = new DateTime(2007,1,1,0,0,0); // we need to pass any year, month and day
        dim textBoxDate as DateTime
        if DateTime.TryParse(textBox1.Text, textBoxDate) then
            dateTimePicker1.Value = textBoxDate
            MessageBox.Show("Unrecognized time format!")
        end if
    end if

    Just for info, value is not just time, but date + time. It only displays time part of the full date.

    LVL 1

    Author Comment

    Hi Priest04

    Thanks again! Just what I needed.


    LVL 18

    Expert Comment

    You are welcome


    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

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    760 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

    6 Experts available now in Live!

    Get 1:1 Help Now