Smarton Smarton - 6 months ago 11
Vb.net Question

How do I set "8:00 AM" as the value of my DateTimePicker

I am trying to set the time on my DateTimePicker value to "8:00 AM" on Form Load (using vb.net) but can't work out how to do it.

I have tried setting the value in the properties of my DateTimePicker to "8:00 AM" but on Form Load it keeps on reverting to the current time.

Current time displayed

enter image description here

I have also tried setting the values on Form Load but now get error

DateTimePicker.Value = Date.Now("8:00 AM")


The error I get based on my code above is:

Expression is not an array or a method, and cannot have an argument list.

I can't work out how to set this values.

Anyone got any ideas ?

Answer

Try this code. it will work

 Dim dtval As String = "8:00 AM"
 dtppick.Value = Convert.ToDateTime(dtval)
Comments