c# - How to set default month and day in the datetimepicker? -


i have searched online , managed find codes set year month , day.

datetimepicker2.value = new datetime(2017,12,31); 

i tried using custom format , not seem work

datetimepicker2.customformat = "dd/mm"; datetimepicker2.value = new datetime(12,31); 

you cannot create datetime object day , month. datetime doesn't have kind of constructor. datetime constructors

so need go kind of "workaround"
- use "dummy" year , when need use date - use month , day properties.

var dummyyear = 2000; datetimepicker2.value = new datetime(dummyyear, 12, 31); 

another workaround use parseexact method create datetime based on format using "dd/mm"

var date = datetime.parseexact("31/12", "dd/mm", cultureinfo.invariantculture);  datetimepicker2.value = date; // 12/31/2017 

notice when did not provide year - current year used.
notice: dd invalid format days should lower case "dd"


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -