Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change/set DateTimePicker value

I am trying to set / change the DateTimePicker value (using vb.net) but can't work out how to do it.

I have added the control to the page and I have tried using the following code but it doesn't work and I can't work out how to set the value during run-time.

DateTimePicker1.Value = Now.Day & "-" & Now.Month & "-" & Now.Year

The format of the control is set to Long and it looks like this when first loaded:

Tuesday, February 26, 2013

But I can't work out how to change it.

The error I get based on my code above is:

Conversion from string "26-2-2013" to type 'Date' is not valid.

Anyone got any ideas ?

like image 653
Aaron Avatar asked Feb 26 '13 06:02

Aaron


Video Answer


1 Answers

I ended up getting it working by doing the following:

DateTimePicker1.Value = New Date(2013, 2, 26)

I was loading the value wrong.

like image 69
Aaron Avatar answered Sep 21 '22 00:09

Aaron