views:

169

answers:

5

I'm using a WinForm DateTime picker and it does a fantastic job of choosing dates, but I don't know how to do times. It looks like a time is associated with the value, so maybe there's a way to use this to pick a time?

If there is no built in way to do this, I'll just create another box for the time and modify the DateTime value from the DateTime picker.

Thanks!

A: 

You can either choose the datepicker to have a "long" date, even only "time" or you can create your custom date.

I always use this format, as it's the most easy one to understand for users (IMHO): yyyy.MM.dd HH:mm

This can be done in the designer the fastest, just change the property.

Image

Or, change it in the program with

YourDatePicker.Format = DateTimePickerFormat.Custom;
YourDatePicker.CustomFormat = "yyyy.MM.dd HH:mm";
ApoY2k
A: 

The DateTimePicker works pretty much like how setting the Windows clock works. If you set the ShowUpDown property to true, it displays a spin control to the right of the DateTimePicker. If you then click on a section of the control, such as the time in hours, and then hit the up or down arrow of the spin control, it will change the time in hours.

Also, if you want to use a custom DateTime format, change the Format property to Custom and set the flags you'd like. For example, MM dddd yyyy HH:mm:ss. For an explanation of all the custom format specifiers, here's the full list of them from MSDN.

Hope that helps.

Xander
A: 

Hi,

You can use the built in DateTime picker by adding a custom format string as follows:

DateTimePicker. ShowUpDown = true;
DateTimePicker.CustomFormat = "hh:mm";
DateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;

Enjoy!

Doug
A: 

Never used it nor test it, but maybe this from MSDN can help.

Oliver