Take the 2-minute tour ×

How can I set a DateTimePicker control to a specific date (yesterday's date) in C# .NET 2.0?

share|improve this question
you really need to specify whether you are working with winforms or webpages. you have 5 tags to work with per question try to use them so that you can get a more specific answer to want you need –  Josh Mein Feb 12 '09 at 13:44

6 Answers 6

up vote 28 down vote accepted

Just need to set the value property in a convenient place (such as InitializeComponent()):

    dateTimePicker1.Value = DateTime.Today.AddDays(-1);
share|improve this answer

You can set the "value" property

dateTimePicker1.Value = DateTime.Today;
share|improve this answer

This oughta do it.

DateTimePicker1.Value = DateTime.Now.AddDays(-1).Date;
share|improve this answer

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.

share|improve this answer

If you want to set a date, DateTimePiker.Value is a DateTime object.

DateTimePiker.Value = new DateTime(2012,05,28);

this is constructor of DateTime

new DateTime(int year,int month,int date);

My Visual is 2012

share|improve this answer

dateTimePicker1.Value = DateTime.Today();

share|improve this answer

Your Answer

