Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a DateTimePicker display an empty string?

I would like to be able to display a DateTimePicker that has a default value of nothing, i.e. no date.

For example, I have a start date dtTaskStart and an end date dtTaskEnd for a task, but the end date is not known, and not populated initially.

I have specified a custom format of yyyy-MM-dd for both controls.

Setting the value to null, or an empty string at runtime causes an error, so how can I accomplish this?

I have considered using a checkbox to control the enabling of this field, but there is still the issue of displaying an initial value..

Edit:
Arguably a duplicate of the question DateTimePicker Null Value (.NET), but the solution I found for my problem is not a solution for that question, so I think it should remain here for others to find..

like image 788
brasskazoo Avatar asked May 11 '09 00:05

brasskazoo


People also ask

How do you make a DatePicker empty?

if user wants to clear date, simply again set its CUSTOM FORMAT property to empty string " ", and set its TAG back to 0. Thats it..

Can DatePicker be null?

You just need to set property valueDefault={null} and the DatePicker will be blank.

What is DateTimePicker (); in JS?

The JavaScript DateTime Picker is a lightweight and mobile-friendly control that allows end users to enter or select date and time values from a pop-up calendar and drop-down time list. It provides month, year, and decade views for quick navigation to the desired date.


1 Answers

Just set the property as follows:

When the user press "clear button" or "delete key" do

dtpData.CustomFormat = " "  'An empty SPACE dtpData.Format = DateTimePickerFormat.Custom 

On DateTimePicker1_ValueChanged event do

dtpData.CustomFormat = "dd/MM/yyyy hh:mm:ss" 
like image 117
Sérgio Domingos Avatar answered Oct 07 '22 00:10

Sérgio Domingos