Finding Sum of the Date plus Number of Days in VB.NET

A few weeks ago, I had introduced how to find the Date Difference between the two Dates in VB.NET. Now, In this article, i will introduce another some twist of the Date Function in VB.NET, in which it will find the sum of the date and the number of days that you are going to add. So, now let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add one DateTimePicker named DateTimePicker1 in the ToolBox. Add also one TextBox named TextBox1 for the inputting of the number of days to add. Then add a button named Button1 labeled as "Compute Date Sum". You must design your layout like this: design 3. Now, put this code in Button1_Click. This will display the result of the Date Sum from the DateTimePicker and the inputted number of days in the TextBox.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim i As Integer
  3.         Dim dt As Date
  4.         dt = DateTimePicker1.Value
  5.         i = Val(TextBox1.Text)
  6.         MsgBox("The date sum is:" & " " & DateAdd(DateInterval.Day, i, dt))
  7.   End Sub

Explanation:

We have initialized dt as Date to hold the value of our DateTimePicker1. It will have a default value of your current Date when you run the program. We also initialized i as integer to be able to input the number of days. Next, the main syntax of this tutorial is the DateAdd(DateInterval.Day, i, dt). We use the DateAdd function to add a specified time interval from a date. To add days to DateValue, we use DateInterval.Day and its value is coming from the input in our textbox as the number of days, and we add it on the dt as it holds the DateTimePicker1 that is equal to Now() or the present date.

Output:

output Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment