DateTimePicker plays essential role in the system development;
it is very useful if you need to input a date, time or even selecting a date
range in your data base. DateTimePicker control in one way or another is comparable
to MonthCalendar Control, these controls both allows you to select a date.
Like any other controls in Visual Basic there are a lot of
methods on how you can manipulate your DateTimePicker. Here are some of the
essentials that you may need to know on how to use and control the DateTimePicker.
1.
You can find the DateTimePicker control under
Common Controls in the Toolbox.
2.
By default a DateTimePicker Format is LONG. (Refer
to the image below). You can change the format by selecting the Format in
Properties Windows and change the value. There are 4 formats to choose from,
LONG, SHORT, TIME and CUSTOM.
3.
DateTimePicker1 is the Default Name of the
control.
4.
In order to change the display font, find
CalendarFont in the Properties Window.
5.
The default value of the control is based on
system date.
6.
To display the DateTimePicker value in a TextBox
you can use the following codes.
a.
SHORT DATE STRING FORMAT
TextBox1.Text = DateTimePicker1.Value.ToShortDateString
b.
LONG DATE STRING FORMAT
TextBox1.Text = DateTimePicker1.Value.ToLongDateString
c.
SHORT TIME STRING FORMAT
TextBox1.Text = DateTimePicker1.Value.ToShortTimeString
d.
LONG TIME STRING FORMAT
TextBox1.Text = DateTimePicker1.Value.ToLongTimeString
7.
You can also add days, month, and
year in your DateTimePicker Value. Below is a sample syntax on how you can add
a days.
ADDING DAYS
SYNTAX:
DateTimePicker.Value.AddDays(Value
As Double)
SAMPLE CODE:
DateTimePicker1.Value = DateTimePicker1.Value.AddDays(10)
ADDING MONTHS
SYNTAX:
DateTimePicker.Value.AddDays(Monhts as Integer)
SAMPLE CODE:
DateTimePicker1.Value = DateTimePicker1.Value.AddMOnths(5)
ADDING YEARS
SYNTAX:
DateTimePicker.Value.AddDays(Value as Integer)
SAMPLE CODE:
DateTimePicker1.Value = DateTimePicker1.Value.AddYears(2)
These are the basics of DateTimePicker Control.
Feel free to comment and ask more about DateTimePicker Control. Happy Coding.