• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1619
  • Last Modified:

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

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?
1 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);

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now