Date and Time in Window Application in VB.NET

In this Article we learn that display particular Date and Time in any Window Form Application with Control.
  • 5714
Introduction:  In this Application learn  how can we Display a Date and Time with DateTimePicker control and MonthCalender control in Windows Application Form.

The DateTimePicker control displays date and/or time information and acts as the interface through which users can modify date and time information.

Step1: Open Visual Studio.

  • Go to file menu and click a project option..
  • Select  visual c# and Window Application and click ok.
  • Open Window Form

Step 2: We put DataTimePicker control and MonthCalender control, Label ,Button control in the Windows Form.


Step 3: Now we click in Month Calender and write a code for display a date.


Private Sub monthCalendar1_DateChanged(sender As Object, e As DateRangeEventArgs)label1.Text = 

Note: Selection range which are  define the range of date for MonthCalender .


Step: 4 Again double click in the form and write a code for display a specific time.


Private Sub Form1_Load(sender As Object, e As EventArgs)label1.Text = monthCalendar1.SelectionRange.Start.ToString()dateTimePicker1.Format = 
DateTimePickerFormat.TimedateTimePicker1.Width = 100dateTimePicker1.ShowUpDown = True End Sub

Note: The DataTimePicker control specifies the Date and Time Format.

  •  UpDown control is used to adjust the Date and Time Value.
  • True represent a Boolean value.

Step 5: Go to again Form Windows and double click on Button Control .

  • When we click in Button Contro alsol find the exact Time and Date


Private Sub button1_Click(sender As Object, e As EventArgs)Dim [Date] As DateTime[Date] = DateTime.NowMessageBox.Show([Date].ToString())
End Sub


  • DateTime.Now represent Date and Time of Day.
  • When we click in button then find a time and date.

With the help of this code we can define a date and time in our application. 



More Articles

© 2020 DotNetHeaven. All rights reserved.