How to Code DateDiff With DateTimePicker in VB.NET
The DateTimePicker VB.NET control provides you with a calendar image from which your users can select a date. You create two DateTimePicker controls on your Web form, so users can choose a "from" and "to" date for a period of time. The "DateDiff" function tells you the number of days between the two chosen dates. This function lets you evaluate the amount of time for chosen dates, so you can either accept or deny the selected values.
Instructions
-
-
1
Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET Framework," then click "Visual Studio" to open the VB.NET program.
-
2
Drag-and-drop two DateTimePicker controls from the toolbox from the left toolbox to the Web form. These two controls are shown to the user so she can select two dates.
-
-
3
Double-click one of the DateTimePicker controls to open the code. Scroll to the VB.NET function you want to use for the DateDiff function. Type the following code to detect the number of days between the two selected dates:
Dim date1 As DateTime
Dim date2 As DateTime
Dim days As Integer
date1 = DateTimePicker1.Value.ToShortDateString
date2 = DateTimePicker2.Value.ToShortDateString
days = DateDiff("d", date1, date2)
-
1