473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is there a way to dynamically set the default value of a DateTimePicker control?

code green
1,726 Expert 1GB
Is there a way to dynamically set the default value of a DateTimePicker control.
So at start-up the date displayed is yesterday's date or one month ago.
Expand|Select|Wrap|Line Numbers
  1. this.dtPickStart.Value = new System.DateTime(2010, 11, 22, 0, 0, 0, 0);
Rather than a literal value as set in 'Properties'
Nov 22 '10 #1

✓ answered by Frinavale

I'm not sure what you are having problems with.
I did this in a Form Load event and it sets a DateTimePicker called DPTest to yesterday's date:

(C#)
Expand|Select|Wrap|Line Numbers
  1. DateTime  yesterday = DateTime.Today.Subtract(new TimeSpan(1)).Date;
  2. DPTest.Value = yesterday;
(VB.NET)
Expand|Select|Wrap|Line Numbers
  1. Dim yesterday As DateTime = DateTime.Today.Subtract(New TimeSpan(1)).Date
  2. DPTest.Value = yesterday
-Frinny

1 3998
Frinavale
9,735 Expert Mod 8TB
I'm not sure what you are having problems with.
I did this in a Form Load event and it sets a DateTimePicker called DPTest to yesterday's date:

(C#)
Expand|Select|Wrap|Line Numbers
  1. DateTime  yesterday = DateTime.Today.Subtract(new TimeSpan(1)).Date;
  2. DPTest.Value = yesterday;
(VB.NET)
Expand|Select|Wrap|Line Numbers
  1. Dim yesterday As DateTime = DateTime.Today.Subtract(New TimeSpan(1)).Date
  2. DPTest.Value = yesterday
-Frinny
Nov 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Gianni | last post by:
I have to insert in a html select the last 10 years <select name="year" onChange="month()" size=5> <option value="1994">1994</option> <option value="1995">1995</option> <option...
9
by: Ed Crowley | last post by:
I have a DateTimePicker control on my form that is displaying the date format in UK format (dd/mm/yy). However, in my code dtpStartDate.Value gives a date in US format, but...
4
by: Jacek Jurkowski | last post by:
.... the minimum date of DateTimePicker is 1753-01-01. How to make DateTime to do not show nothing in its text if this date is the value? I have a form with a field LastLogonDate. If user hasn't...
4
by: Maria | last post by:
I've tried to search for a way to set a datetimepicker.value to nothing. I would like it to display nothing until the user select a value.. I know you can use a checkbox to disable the control -...
0
by: simchajoy2000 | last post by:
Hi, I have a VB.NET form with several DateTimePickers on it. These have worked great for me until several days ago. All of a sudden they no longer recognize user input. So if a user enters a...
7
by: Clamara | last post by:
When adding a new record from my form, I pre-set my DateTimePicker's value to System.DateTime.Today Since the "Today" value is used most of the time, the user doesn't need to select a date from...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
1
by: Kevin | last post by:
I have put a VS2005 sample project up here: http://www.kevinandkiran.com/CSharpApplication.zip (its only 50k) Basically I have a class that contains a date property, which is initialised to...
4
by: jehugaleahsa | last post by:
Hello: We were hoping to allow users to have DateTimePicker value null so that a unused date is stored on a Database. Does the control support this? I am pretty sure it doesn't. How would you...
5
by: mcfly1204 | last post by:
I am using a DateTimePicker in a Windows Form app., but the value is always the current date. I am displaying the value of the picker in a label when a button is clicked, but the value does not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.