DateTimePick Question

M

Mr. B

How can one (if it's possible) change the date in DateTimePicker via code?

Extracting it is easy enough...
Dim MyDate As Date
Dim MyMonth As String
MyDate = DateTimePicker1.Value.Date

But I'd like to be able to click a Button (one of several) and add or subtract
a day or more via the button.

Possible without changing the PC system date?

Thanks

Bruce
 
A

Armin Zingler

Mr. B said:
How can one (if it's possible) change the date in DateTimePicker via
code?

Extracting it is easy enough...
Dim MyDate As Date
Dim MyMonth As String
MyDate = DateTimePicker1.Value.Date

But I'd like to be able to click a Button (one of several) and add or
subtract a day or more via the button.

Possible without changing the PC system date?

DateTimePicker1.Value = DateTimePicker1.Value.AddDays(-3)
 
H

Herfried K. Wagner [MVP]

* Mr. B said:
How can one (if it's possible) change the date in DateTimePicker via code?

Extracting it is easy enough...
Dim MyDate As Date
Dim MyMonth As String
MyDate = DateTimePicker1.Value.Date

But I'd like to be able to click a Button (one of several) and add or subtract
a day or more via the button.

Just set the 'Value' property (sample taken from MSDN library):

\\\
Public Sub New()
' Create a new DateTimePicker
Dim dateTimePicker1 As New DateTimePicker()
Controls.AddRange(New Control() {dateTimePicker1})
MessageBox.Show(dateTimePicker1.Value.ToString())

dateTimePicker1.Value = DateTime.Now.AddDays(1)
MessageBox.Show(dateTimePicker1.Value.ToString())
End Sub
///
 
M

Mr. B

With said:
Just set the 'Value' property (sample taken from MSDN library):

Hmmm... Thanks! Armins seems simple vs. yours. However, I'll try them both
and see what happens in my situation requirements.

Many thanks!

Bruce
 
H

Herfried K. Wagner [MVP]

* Mr. B said:
Hmmm... Thanks! Armins seems simple vs. yours. However, I'll try them both
and see what happens in my situation requirements.

It's the same solution... setting the 'Value' property to a 'DateTime'.

;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top