Visual Studio .NET's DateTimePicker control offers a convenient way for users to make a date/time selection. The control allows you to select dates and times and to skip the date format validity of the data since the control lets you limit the input.
DateTimePicker is similar to the MonthView control, which allows you to select either a date or a range of dates but doesn't support time selection. In this quick tip, I will create an example that uses the DateTimePicker control.
Example
Find the DateTimePicker control in the Toolbox under the Common Controls section and add it to the Windows Form. Set the following properties:
|> Name: dtpDateSelection
|> CustomFormat: mm/dd/yyyy
|> Format: short
|> MaxDate: 12/31/2008
|> MinDate: 01/01/2007
|> ShowUpDown: False
Add the following code to the Form Load event:
dtpDateSelection.Value = Now
Create the following event:
Private Sub dtpDateSelection_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpDateSelection.CloseUp
MessageBox.Show(dtpDateSelection.Value)
End Sub
Result
In the first example, the ShowUpDown property is set to False, which means that the control's calendar portion is visible when the user clicks the control. The user then picks the date from the control's calendar portion. Select a date on the DateTimePicker control, and your screen will look similar to Figure A (http://www.builderau.com.au/builder/i/s/VB0726_FigA.gif).
Now change the ShowUpDown property value to True and run the code again. You will not see the control's calendar portion, and you will be able to pick a date by clicking the up/down arrows of the control. The result will look like Figure B (http://www.builderau.com.au/builder/i/s/VB0726_FigB.gif).
Notice that the control will not allow you to pick a date that's smaller than the MinDate property value or larger than the MaxDate property value.
For more information
There are many other properties and important methods you can use to get the DateTimePicker control to behave the way you want. MSDN offers additional details about how to use the DateTimePicker control.






1
marwa - 12/12/07
how can i make datetimepicker make search to get data that i put it in the textbox
» Report offensive content
2
richter belmont - 26/01/08
how can i disable the textbox in the datetimepicker control so that the user can only use the calendar to input values not on the textbox?
Offensive content reported3
Pralhad Sawant - 15/03/08
I want to store the value of datetimepicker control in database datetime datatype col. When i try then It rise the exception out of range
Offensive content reported4
phillip - 10/04/08
How do calculate the number of days between 2 dateTimePickers
» Report offensive content
5
Mircea - 02/05/08
@phillip
Offensive content reportedHello
You could calculate that number of days like this:
Dim x As Integer
x = DateTimePicker1.Value.Day - DateTimePicker2.Value.Day
MsgBox(x)
I think you`ll manage to make it work.
Bye
6
SasiKumar.K - 18/07/08
Nice
» Report offensive content
7
Rex - 29/08/08
You know when you drop down a datetimepicker a calendar shows up. At the top of the calendar Month and Year displays.
Does anybody know how to make Year invisible?
Thanks.
» Report offensive content
8
anand - 15/09/08
How can i store the value from datetimepicker in to the database in ms-access.
Offensive content reported9
tony - 26/09/08
How do you select the time.
In none of your examples to you show how to select the time.
» Report offensive content
10
Esaau - 02/10/08
Hi everyone.
Can please someone help me here. I want to write a code that writes from the textbox to the datetimepicker.
For instance, when I write a date of birth from the textbox, that value may be populated in the datetimepicker control
» Report offensive content
11
Kingsley - 10/10/08
Hi gang,
Offensive content reportedhow can i display in the dropdown calender of the datetimepicker only the weekdays or maybe make the weekend days unclickerble
12
FelixNicol - 23/10/08
Ty, that was just the event I needed for validating a period made of 2 dates (begin and end)!
» Report offensive content
13
jigisha - 18/04/09
how to put datetime picker value in crytal report
» Report offensive content
14
chinna - 10/08/09
about addition of date
» Report offensive content
15
Lester Marquez - 29/08/09
how can I remove the time on your codings
your code response this output:
ex: 08/08/2009 11:30am
but, how can I Remove the time?
I am Using Label into my output
I just need the date...
thanks...
» Report offensive content
16
tani - 03/09/09
i m not getting the time...in datetimepicker..m only getting the date..wat will b the property change or coding..plz help..using visual studio 2005
» Report offensive content
17
SITHARTHAN MANI - 18/09/09
I have clicked datetimepicker object, popup shown. Meanwhile, i have close that particular form, but popup was not closed that time. Stil it is shown.
When i go to next step, i am getting access violation error.
Anybody can help me, to close datetimepicker instance when i close that particular form
» Report offensive content
18
atin - 24/09/09
how can i, with the help of datetime picker get the time up to date
Offensive content reported19
Arun - 12/10/09
all controls code in c#
» Report offensive content
20
Aaron - 21/11/09
I have a program that records dates to an access database. I am trying to search through those records using 2 datetimepicker controsl, by checking to see if the database records are <, > the datetimepicker controls. The problem is wierd, when the computer sorts through the dates it goes through a numberical sort order, and not by actual date, such as 1,10,11,12,13,14....18,19,2,20,21,21...etc
I have the date formatted everywhere as custom,(dd/MM/yyyy).
How can I get it to add day by day, from the first to the second and then the third, and so on?
» Report offensive content
21
ct virus - 09/12/09
how to compare to two year in date time picker control in vb.net
» Report offensive content
22
Hav0c - 28/01/10
Hey
I have a date â2010/01/27â (yyyy/mm/dd) in my Access database stored as a sting now I know how to get it from the database using a OleDbDataReader now the question is How do I display that date â2010/01/27â in my DateTimePicker as â12 January 2010â ??
» Report offensive content
23
Hav0c - 28/01/10
Hey
I am storing the date that I get from a DateTimePicker as a string in my ms access database
dtpDOB is my DateTimePicker variable name
» Report offensive content
24
puja - 03/05/10
How can i assign a value to the datetimepicker?the value of date in datetimepicker should be 1 month prior to current date
» Report offensive content
25
Nilesh Vat - 25/05/10
I want to see the birthday on today in a school management software in vb.net. For this i need only to compare the date and month only not year. So how can i do this pls help me in this case.
» Report offensive content
26
felix beto - 03/07/10
como podemos realiar la codificacion con el datetimepicker
» Report offensive content