Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

C# DateTimePicker Control



The DateTimePicker control allows you to display and collect date and time from the user with a specified format.

The DateTimePicker control has two parts, a label that displays the selected date and a popup calendar that allows users to select a new date. The most important property of the DateTimePicker is the Value property, which holds the selected date and time.

dateTimePicker1.Value = DateTime.Today;

The Value property contains the current date and time the control is set to. You can use the Text property or the appropriate member of Value to get the date and time value.

DateTime iDate;
iDate = dateTimePicker1.Value;

The control can display one of several styles, depending on its property values. The values can be displayed in four formats, which are set by the Format property: Long, Short, Time, or Custom.

dateTimePicker1.Format = DateTimePickerFormat.Short;

Convert String to DateTime

You can use the methods like Convert.ToDateTime(String), DateTime.Parse() and DateTime.ParseExact() methods for converting a string-based date to a System.DateTime object. More about….. String to DateTime

How to find the date difference?

The DateTime.Subtract method may be used in order to find the date-time difference between two instances of the DateTime method. More about….. Find date difference

How to set DateTime object to null?

By default, DateTime is not nullable because it is a Value Type, using the nullable operator introduced in C# 2, you can achieve this. More about….. Datetime object to null
The following C# program shows how to set and get the value of a DateTimePicker1 control.


Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More