C#.NET VS 2005: Setting the seconds of DATETIMEPICKER  value to zero but taking a time and date from the user

Posted on 2007-10-12
Last Modified: 2013-12-17
C#.NET VS 2005 DateTime obect.  I have a System.Windows.Forms.DateTimePicker component that is getting a start time from the user.  For example, the user choses 9/19/07 at 01:35:PM.  However, what they are getting is 09/19/2007  1:35:13 PM.  The seconds is choosen by the system but I need to get it so that the seconds are set to zero and the rest of the time and date is set as the user wants it.  How does one allow users to set a DateTimePicker object so that the user picks the time, but the seconds are automatically set to 00?
Question by:alexmcferron
    1 Comment
    LVL 22

    Accepted Solution

    One option is to replace the selected DateTime with a new one that sets the seconds to zero, as:
    DateTime selected = new DateTime(yourDateTimePicker.Value.Year,
                                     yourDateTimePicker.Value.Minute, 0);


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    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…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    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…

    761 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

    15 Experts available now in Live!

    Get 1:1 Help Now