How can I set a DateTimePicker control to a specific date (yesterday's date) in C# .NET 2.0?
+3
A:
Just need to set the value property in a convenient place (such as InitializeComponent()
):
dateTimePicker1.Value = DateTime.Today.AddDays(-1);
Rowland Shaw
2009-02-12 13:37:32
k gotcha but he does need to be a little more specific then
jmein
2009-02-12 13:40:21
Just retagged as this was accepted as the answer...
Rowland Shaw
2009-02-12 13:41:56
A:
This oughta do it.
DateTimePicker1.Value = DateTime.Now.AddDays(-1).Date;
Jason Punyon
2009-02-12 13:38:12
+1
A:
You can set the "value" property
dateTimePicker1.Value = DateTime.Today;
Sessiz Saat
2009-02-12 13:42:16
A:
Use the Value
property.
MyDateTimePicker.Value = DateTime.Today.AddDays(-1);
DateTime.Today
holds today's date, from which you can subtract 1 day (add -1 days) to become yesterday.
DateTime.Now
, on the other hand, contains time information as well. DateTime.Now.AddDays(-1)
will return this time one day ago.
lc
2009-02-12 13:44:21